n = int(input()) ans = [y-x for x,y in [map(int, input().split()) for _ in range(n)]] if ans[0] > 0 and all(ans[i]==ans[0] for i in range(n)): print(ans[0]) else: print(-1)