n=int(input()) a=list(map(int,input().split())) b=list(map(int,input().split())) ans=0 for x in range(n): c=b[x]-a[x] ans+=c if n==2: if a[0]-b[0]==-1*(a[1]-b[0]): print(abs(a[0]-b[0])) else: print(-1) else: if ans%(2-n)==0: ans1=ans//(2-n) ch=0 out=0 for u in range(n): e=b[u]-a[u] if (e+ans1)%2==1: out+=1 ch+=(e+ans1)//2 if out==0 and ch==ans1: print(ans1) else: print(-1)