N = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) if N == 2: if sum(A) == sum(B): print(abs(A[0] - B[0])) else: print(-1) elif N > 2: if (sum(A) - sum(B)) % (N - 2) == 0: print((sum(A) - sum(B)) // (N - 2)) else: print(-1)