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 n == 2: if sum(a) != sum(b): print(-1) else: print(abs(a[0] - b[0])) exit() 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)