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]-a[1]))
  else:print(-1)
  exit()
if sum(a)>=sum(b) and (sum(a)-sum(b))%(n-2)!=0:exit(print(-1))
ans=(sum(a)-sum(b))//(n-2)
c=[0]*n
for i in range(n):
  c[i]=(b[i]-(a[i]-ans))//2
  if (b[i]-(a[i]-ans))<0 or (b[i]-(a[i]-ans))%2==1:exit(print(-1))
if sum(c)==ans:print(ans)
else:print(-1)