N = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) mx = 0 for a, b in zip(A, B): mx = max(mx, a - b) ans = 0 for a, b in zip(A, B): ans += mx - (a - b) print(mx if ans == mx * 2 else -1)