n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) if n == 2: if sum(a) == sum(b): print(abs(a[0] - b[0])) else: print(-1) else: t = sum(a) - sum(b) if t >= 0 and t % (n - 2) == 0: t //= n - 2 res = 0 for i in range(n): k = b[i] - a[i] + t if k < 0: print(-1) break res += k else: if res // 2 == t: print(t) else: print(-1) else: print(-1)