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