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