N=int(input()) A=list(map(int,input().split())) B=list(map(int,input().split())) D=[a-b for a,b in zip(A,B)] if N==2: if sum(D)==0: ans=0 else: ans=-1 else: if sum(D)<0 or sum(D)%(N-2): ans=-1 else: cnt=sum(D)//(N-2) for i in range(N): A[i]-=cnt if all(a<=b and b%2==b%2 for a,b in zip(A,B)): ans=cnt else: ans=-1 print(ans)