while True:
    try:
        # 初始化表格
        m, n = map(int, input().split())
        if m > 9 or n > 9:
            print('-1')
        else:
            print('0')
        
        # 交换坐标
        x1, y1, x2, y2 = map(int, input().split())
        if 0 <= x1 < m and 0 <= x2 < m and 0 <= y1 < n and 0 <= y2 < n:
            print('0')
        else:
            print('-1')
        
        # 插入行
        x = int(input())
        if m < 9 and 0 <= x < m:
            print('0')
        else:
            print('-1')
        
        # 插入列
        y = int(input())
        if n < 9 and 0 <= y < n:
            print('0')
        else:
            print('-1')
        
        # 查找坐标
        x, y = input().split()
        x, y = int(x), int(y)
        if 0 <= x < m and 0 <= y < n:
            print('0')
        else:
            print('-1')

    except EOFError:
        break