def solve(): N = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) if N==2: if sum(A)!=sum(B) or (A[0]-B[0])%2==1: return -1 return abs(A[0]-B[0])//2 if (sum(A)-sum(B))%(N-2)!=0: return -1 cnt = (sum(A)-sum(B))//(N-2) B = list(map(lambda x:(x+cnt),B)) for i in range(N): if (B[i]-A[i])%2==1: return -1 return cnt print(solve())