n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) diff = 0 for i in range(n): diff += a[i] - b[i] if diff % (n - 2) == 0 and diff // (n - 2) > 0: cnt = diff // (n - 2) else: print(-1) exit() for i in range(n): d = cnt - (a[i] - b[i]) if d % 2 == 0 and d >= 0: continue else: print(-1) exit() print(cnt)