N = int(raw_input()) g = set([]) for i in range(N): x, y = map(int, raw_input().split()) if x >= y: print -1 break else: g.add(y - x) if len(g) > 1: print -1 elif i == N - 1: print g.pop()