# 嘘解法の提出。WA になるべき。 import sys import numpy as np read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N = int(readline()) A = np.array(readline().split(), np.int64) B = np.array(readline().split(), np.int64) def main(A, B): N = len(A) SA, SB = A.sum(), B.sum() if N == 2: if SA != SB: return -1 return np.abs(A - B).sum() // 2 K = (SA - SB) // (N - 2) A -= K x = B - A # if np.all((x >= 0) & (x % 2 == 0)): if np.all(x >= 0): return K else: return -1 print(main(A, B))