n = int(input()) x,y = map(int,input().split()) c = y-x cou = 1 for i in range(n-1): x,y = map(int,input().split()) if y-x == c: cou += 1 if n != cou or x>y: print(-1) else: print(c)