import sys; input = sys.stdin.buffer.readline sys.setrecursionlimit(10**7) from collections import defaultdict con = 10 ** 9 + 7; INF = float("inf") def getlist(): return list(map(int, input().split())) #処理内容 def main(): N = int(input()) A = getlist() B = getlist() for i in range(N): A[i] -= B[i] if N == 2: if sum(A) == 0: print(abs(A[0])) else: print(-1) return dif = sum(A) if dif % (N - 2) != 0: print(-1) return n = int(dif // (N - 2)) # 2 * aplha = n - A[i] cnt = 0 for i in range(N): if (n - A[i]) % 2 == 1 or n - A[i] < 0: print(-1) return cnt += int((n - A[i]) // 2) if cnt == n: print(n) else: print(-1) if __name__ == '__main__': main()