import sys sys.set_int_max_str_digits(100000) a,b,c=input().split() A,B,C=input().split() print(-1 if b==B else (a,A)[int(b)