#题干复杂,编程简单
#注意不要越界即可
while True:
    try:
        m, n = map(int, input().split())
        if m <= 9 and m > 0 and n <= 9 and n > 0:
            print(0)
        else:
            print(-1)
        x1, y1, x2, y2 = map(int, input().split())
        if x1 >= 0 and y1 >= 0 and x2 >= 0 and y2 >= 0 and x1 < m and x2 < m and y1 < n and y2 < n:
            print(0)
        else:
            print(-1)

        x = int(input())
        if x >= 0 and x < m and m + 1 <= 9:
            print(0)
        else:
            print(-1)

        y = int(input())
        if y >= 0 and y < n and n + 1 <= 9:
            print(0)
        else:
            print(-1)

        x, y = map(int, input().split())
        if x >= 0 and y >= 0 and x < m and y < n:
            print(0)
        else:
            print(-1)
    except:break