def main(): N = int(input()) if N == 1: a = int(input()) b = int(input()) if b < a: return -1 return b - a A = list(map(int, input().split())) B = list(map(int, input().split())) sa = sum(A) sb = sum(B) if N == 2: if sa != sb: return -1 return abs(A[0] - B[0]) if sb > sa: return -1 if (sa - sb) % (N - 2) != 0: return -1 K = (sa - sb) // (N - 2) dec = 0 add = [0] * N for i in range(N): if A[i] < B[i]: dec += B[i] - A[i] add[i] += 2 * (B[i] - A[i]) if dec > K: return -1 return K # K -= dec # for i in range(N): # A[i] += add[i] - dec # print(A, dec) # print(B) print(main())