n=int(input()) *a,=map(int,input().split()) *b,=map(int,input().split()) dif=sum(a)-sum(b) if n==2: if dif!=0: print(-1) else: print(abs(a[0]-b[0])) elif dif>=0 and dif%(n-2)==0: x=dif//(n-2) for i in range(n): if (b[i]-(a[i]-x))%2==1: print(-1) exit() print(x) else: print(-1)