N = int(input()) L = [] for _ in range(N): x, y = map(int, input().split()) L += [y - x] L = sorted(set(L)) print([-1, L[0]][len(L) == 1 and L[0] > 0])