#include #include using namespace std; int main() { std::ios::sync_with_stdio(false); std::cin.tie(0); int n; cin >> n; int x = 0; int y = 0; vector vec; int ans = -1; for (int i = 0; i < n; ++i) { cin >> x >> y; if (x >= y) { break; } else { vec.push_back(y - x); } } if (!vec.empty()) { ans = vec.at(0); for (size_t j = 0; j < vec.size(); ++j) { if (ans != vec.at(j)) { ans = -1; break; } } } cout << ans << endl; return 0; }