#include #include #include #include #include #include int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int n; std::cin >> n; std::vector> lr(n); for (auto& [l, r] : lr) std::cin >> l >> r; std::sort(lr.begin(), lr.end()); int ans = 0; for (int k = 0; k < lr.back().first; ++k) { bool ok = true; std::priority_queue, std::greater> pq; for (int i = 1, j = 0; i <= n; ++i) { while (j < n and lr[j].first <= k + i) { pq.push(lr[j++].second); } if (pq.empty() or pq.top() < k + i) { ok = false; break; } pq.pop(); } if (ok) { ++ans; } } std::cout << ans << std::endl; }