l = [] for _ in range(2): s, p, _ = input().split() l.append([p, s]) l = sorted(l) print([-1, l[1][1]][l[0][0] != l[1][0]])