import numpy as np import sys N = int(input()) A = np.array(input().split(), dtype=np.int64) B = np.array(input().split(), dtype=np.int64) C = B - A m = abs(C.min()) count = 0 while count <= m: S = np.unique(C) if len(S) == 2 and S.sum() == 0: count += abs(S[0]) print(count) sys.exit() D = np.full(N, abs(C.min() + C.max())) D[C.argmax()] *= -1 C = C + D count += abs(D[0]) print(-1)