N = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) if N==2 and B[0]-A[0] == -(B[1]-A[1]): print(abs(B[0]-A[0])) elif N == 2: print(-1) exit() s = 0 m = [] for i in range(N): s += (B[i]-A[i]) m.append(B[i]-A[i]) sm, mod = divmod(s, 2-N) if mod != 0: print(-1) exit() else: res = 0 for i in range(N): if (m[i]+sm)%2 == 1: print(-1) exit() else: res += abs((m[i]+sm)//2) print(res)