N=int(input()) X = [[int(i) for i in input(). split ()] for i in range(2)] d=X[0][1]-X[0][0] nd=1 i=0 while nd==1 and i<2: if X[i][1]-X[i][0]!=d: print (-1) nd=0 i+=1 print(d)