N = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) up = 0 maxv = 0 for i in range(N): maxv = max(maxv, B[i] - A[i]) up += (B[i] > A[i]) if up != 1 and A != B: print(-1) exit() if N == 2: if sum(A) == sum(B): print(maxv) else: print(-1) else: for i in range(N): if B[i] > A[i]: A[i] += maxv else: A[i] -= maxv S = 0 for i in range(N): S += A[i] - B[i] if B[i] > A[i]: print(-1) exit() if S % (N - 2) == 0: print(S//(N-2) + maxv) else: print(-1)