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