while True: try: initial_table_list = list(map(int,input().split())) row = initial_table_list[0] column = initial_table_list[1] switch_list = list(map(int,input().split())) x1 = switch_list[0] y1 = switch_list[1] x2 = switch_list[2] y2 = switch_list[3] insert_row = int(input()) insert_column = int(input()) # check coordinate x3,y3 = list(map(int,input().split())) if 1<= row <=9 and 1<= column <=9: print(0) else: print(-1) if 0 <= x1 < row and 0 <= x2< row and 0 <= y1 < column and 0 <= y2 < column: print(0) else: print(-1) if row<=8 and insert_row<=row-1: print(0) else: print(-1) if column <= 8 and insert_column<= column-1: print(0) else: print(-1) if 0 <= x3 < row and 0 <= x3< row: print(0) else: print(-1) except: break