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