N = int(input()) A = list(map(int,input().split())) B = list(map(int,input().split())) for i in range(N): A[i] -= B[i] suma = sum(A) if N == 2: if suma != 0: print(-1) else: print(abs(A[i])) exit() if suma % (N - 2) != 0: print(-1) exit() tot = suma // (N-2) if max(A) > tot: print(-1) exit() ans = 0 for i in range(N): if (tot - A[i]) % 2 != 0: print(-1) exit() print(tot)