N=int(input()) X=[0]*N Y=[0]*N cnt=0 for _ in range(N): X[_],Y[_]=list(map(int,input().split())) k=Y[0]-X[0] if 0<=k and k<=N: for i in range(N): cnt+=(Y[i]-X[i]) if cnt==k*N: print(k) else: print(-1) else: print(-1)