import sys n = int(input()) a,b = map(int,input().split()) s = b-a if s <= 0: print(-1) sys.exit() for i in range(n-1): a,b = map(int,input().split()) if s != b-a: print(-1) sys.exit() print(s)