n = int(input()) a = [int(i) for i in input().split()] b = [int(i) for i in input().split()] li = [0]*n ans = 0 parity = (b[0]-a[0])%2 for i in range(n): li[i] = b[i]-a[i] if li[i] % 2 != parity: print(-1) exit() li.sort(reverse=True) f = True for i in range(n): if li[i] != 0: f = False break if f == True: print(0) exit() if li[n-1] > 0: print(-1) exit() ttl = -li[n-1] itr = 10**7 hiku = 0 tasu = 0 for i in range(n): tmp = (ttl+li[i])//2 tasu += tmp hiku += ttl-tmp #print(tasu,hiku,"ttl?") if tasu*(n-1) == hiku: print(ttl) exit() for i in range(itr): tasu += n hiku += n ttl += 2 if tasu*(n-1) == hiku: print(ttl) exit() print(-1)