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<SB:
    print(-1)
    exit()
k=(SA-SB)//(N-2)
for i in range(N):
    a,b=A[i]-k,B[i]
    if b-a<0 or (b-a)%2!=0:
        print(-1)
        exit()
print(k)