n = int(input()) z = 0 for i in range(n): x, y = map(int, input().split()) if i == 0: z = y - x if z != y - x or y - x <= 1: print(-1) break else: print(z)