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