def f(q): try: return int(q) except ValueError: return q q=sorted([list(map(f,input().split())) for i in range(2)],key=lambda x:x[1],reverse=True) if q[0][1]==q[1][1]: print(-1) else: print(q[0][0])