n1, y1, _ = input().split() n2, y2, _ = input().split() y1, y2 = map(int, [y1, y2]) if y1 == y2: print(-1) else: print(n1 if y1 > y2 else n2)