n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) if n == 2: if sum(a) != sum(b): print(-1) else: print(abs(a[0] - b[0])) else: d = sum(a) - sum(b) if d < 0 or d % (n - 2) != 0: print(-1) else: d //= n - 2 s = 0 for i in range(n): x = b[i] - a[i] + d if x < 0 or x % 2 == 1: print(-1) break else: print(d)