def create_table(x,y):
if 0 < x <= 9 and 0 < y <= 9:
global mytable
mytable = [[i + j for j in range(y)] for i in range(x)]
print('0')
else:
print('-1')
def func(x,a):
return True if x in range(a) else False
def exchange_value(x1,y1,x2,y2):
if all(map(func,[x1,x2],[a,a])) and all(map(func,[y1,y2],[b,b])):
mytable[x1][y1],mytable[x2][y2] = mytable[x2][y2],mytable[x1][y1]
print('0')
else:
print('-1')
def add_row(x):
if func(x,a) and a + 1 <= 9:
mytable.insert(x-1, [j for j in range(b)])
mytable.pop()
print('0')
else:
print('-1')
def add_colomn(y):
if func(y,b) and b + 1 <= 9:
for i in range(a):
mytable[i].insert(y-1, i)
mytable[i].pop()
print('0')
else:
print('-1')
def check_cell(x,y):
if func(x,a) and func(y,b):
print('0')
else:
print('-1')
while True:
try:
a,b = map(int,input().split())
create_table(a, b)
c,d,e,f = map(int,input().split())
exchange_value(c,d,e,f)
g = int(input())
add_row(g)
h = int(input())
add_colomn(h)
k,l = map(int,input().split())
check_cell(k,l)
except:
break