N = int(input()) lst = [] for i in range(N): X, Y = map(int,input().split(' ')) A = Y - X lst.append(A) L = len(set(lst)) if L == 1 and A > 0: print(A) else: print('-1')