n = int(input()) a = list(map(int,input().split())) b = list(map(int,input().split())) sa = sum(a) sb = sum(b) if n == 2: dif = a[0]-b[0] if a[1]+dif == b[1]: print(abs(dif)) else: print(-1) exit() if sb > sa or (sa-sb)%(n-2) != 0: print(-1) else: count = (sa-sb)//(n-2) x = 0 for i in range(n): dif = a[i]-b[i] if dif == count: continue if dif >= 0: if (count-dif)%2: print(-1) exit() x += (count-dif)//2 else: if (count+dif)%2: print(-1) exit() x += -dif + (count+dif)//2 if x == count: print(count) else: print(-1)