#include #include #include int main() { int num, x, y; std::cin >> num; std::vector ans; for (int i = 0; i < num; i++) { std::cin >> x >> y; ans.push_back(y - x); } if (std::count(ans.begin(), ans.end(), ans[0]) != ans.size()) { std::cout << -1 << std::endl; } else if(ans[0] < 0){ std::cout << -1 << std::endl; } else { std::cout << ans[0] << std::endl; } return 0; }