N = int(input()) L = [] counter = 0 for i in range(N) : X,Y = map(int,input().split()) Z = Y-X if Z > 0 : L.append(Z) else : counter += 1 L.append(Z) a = L[0] b = L.count(a) if b == N and counter == 0 : print(a) else : print(-1)