a,b,c=input().split() d,e,f=input().split() b_i=int(b) e_i=int(e) if b_i==e_i: print(-1) elif e_i