import numpy as np N = int(input()) A = np.array([int(x) for x in input().split()]) B = np.array([int(x) for x in input().split()]) def main(A,B): if N == 2: if sum(A) != sum(B): return -1 else: return abs(A[0] - B[0]) else: if sum(A) < sum(B) or (sum(A) - sum(B)) % (N - 2) != 0: return -1 t = (sum(A) - sum(B)) // (N - 2) A -= t x = B - A if np.all((x >= 0) & (x % 2 == 0)): return t else: return -1 print(main(A,B))