while True: try: m, n = map(int, input().split()) x1, y1, x2, y2 = map(int, input().split()) x, y = int(input()), int(input()) x3, y3 = map(int, input().split()) print(0 if m <= 9 and n <= 9 else -1) print(0 if x1 < m and x2 < m and y1 ...