n = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) tota = sum(A) totb = sum(B) if n == 2: if tota == totb: print(abs(A[0] - B[0])) else: print(-1) exit() d = tota - totb if d < 0: print(-1) exit() if d % (n - 2) != 0: print(-1) exit() cnt = d // (n - 2) A = [a - cnt for a in A] tot = sum(max(a - b, 0) for a, b in zip(A, B)) if tot < cnt: print(-1) else: print(cnt)