n=int(input()) a=[[int(i) for i in input().split()] for i in range(n)] b=[0 for i in range(n)] for i in range(len(a)): b[i]=a[i][1]-a[i][0] jud=0 for i in range(n): if b[i]!=b[0] or b[i]<0: jud+=1 if jud==0: print(b[0]) else: print(-1)