N = int(input()) L = [] for _ in range(N): X, Y = map(int, input().split()) L += [Y - X] Z = list(set(L)) print([-1, *Z][len(Z) == 1 and Z[0] > 0])