N = int(input()) A = list(map(int,input().split())) B = list(map(int,input().split())) m = [] for i in range(N): m.append(A[i]-B[i]) if N == 2: if sum(A) != sum(B): print(-1) else: print(abs(A[0]-B[0])) exit() sm = sum(m) if sm % (N-2) != 0: print(-1) exit() res = sm//(N-2) for i in range(N): m[i] -= res cnt = 0 for i in range(N): if m[i]%2!=0 or m[i]>0: print(-1) exit() cnt += -m[i]//2 if cnt > res: print(-1) exit() print(res)