## https://yukicoder.me/problems/no/1120 def main(): N = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) sum_b = sum(B) sum_a = sum(A) if N == 2: if sum_a == sum_b: return abs(A[0] - B[0]) else: return -1 else: diff = sum_a - sum_b if diff % (N - 2) != 0: print(-1) return n = diff // (N - 2) sum_n = 0 for i in range(N): d = A[i] - B[i] x = n - d if x % 2 != 0: print(-1) return sum_n += x // 2 if sum_n != n: print(-1) return else: print(n) if __name__ == '__main__': main()