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