N=int(input()) A=list(map(int,input().split())) B=list(map(int,input().split())) S=sum(A)-sum(B) if N==2: if S==0: print(abs(A[0]-B[0])) exit() else: print(-1) exit() if S%(N-2)!=0: print(-1) exit() else: Q=S//(N-2) if Q<0: print(-1) exit() else: check=0 for i in range(N): a=A[i]-Q b=B[i] if a>b or (b-a)%2==1: print(-1) exit() else: check+=(b-a)//2 if check==Q: print(Q) exit() else: print(-1) exit()