def func():
m, n = list(map(int, input().split()))
if 1 <= m <= 9 and 1 <= n <= 9:
print('0')
else:
print('-1')
x1, y1, x2, y2 = list(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 0 <= x < m and m < 9:
print('0')
else:
print('-1')
y = int(input())
if 0 <= y < n and n < 9:
print('0')
else:
print('-1')
x, y = list(map(int, input().split()))
if 0 <= x < m and 0 <= y < n:
print('0')
else:
print('-1')
while True:
try:
func()
except EOFError:
break