import sys input=lambda: sys.stdin.readline().rstrip() n=int(input()) A=[int(i) for i in input().split()] B=[int(i) for i in input().split()] if n==2: if sum(A)==sum(B): print(abs(A[0]-B[0])) else: print(-1) else: d=sum(A)-sum(B) if d<0 or d%(n-2)!=0: print(-1) else: ans=d//(n-2) ct=0 Chk=True for i in range(n): if (B[i]-A[i]+ans)%2!=0 or (B[i]-A[i]+ans)<0: Chk=False ct+=(B[i]-A[i]+ans)//2 if Chk==False or ct!=ans: print(-1) else: print(ans)