n = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) S = 0 for a, b in zip(A, B): S += a-b #print(S) if S%(n-2) == 0: x = S//(n-2) for a, b in zip(A, B): if b-a+x < 0: print(-1) exit() else: if (b-a+x)%2 != 0: print(-1) exit() else: print(x) else: print(-1)