n = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) D = [] for i in range(n): D.append(B[i] - A[i]) sumD = sum(D) if n == 2: if sumD == 0: print(abs(D[0])) else: print(-1) elif sumD < 0 and abs(sumD) % (n - 2) == 0: cnt = abs(sumD) // (n - 2) res = 0 for i in range(n): if D[i] + cnt < 0 or (D[i] + cnt) % 2 != 0: print(-1) exit() res += (D[i] + cnt) // 2 if res == cnt: print(cnt) else: print(-1) else: print(-1)