n = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) if n == 2: if B[0]-A[0] != A[1]-B[1]: print(-1) exit() else: print(abs(B[0]-A[0])) exit() 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)