N=int(input()) A=list(map(int, input().split())) B=list(map(int, input().split())) SA=sum(A) SB=sum(B) if N==2: if SA!=SB: print(-1) exit() else: print(abs(A[0]-B[0])) exit() if (SA-SB)%(N-2)!=0 or SA