N = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) SA, SB = sum(A), sum(B) if N == 2: if SA == SB: print(abs(A[0] - B[0])) else: print(-1) else: if (SA - SB) % (N - 2): print(-1) exit() n = (SA - SB) // (N - 2) for i in range(N): A[i] -= n for i in range(N): if B[i] - A[i] < 0 or (B[i] - A[i]) % 2: print(-1) exit() print(n)