#include using namespace std; static inline void solve() { int n, m; cin >> n >> m; vector> P(m); for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; P[i] = {b, a}; } sort(P.begin(), P.end()); int now = 1; int ans = 2 * (n - 1); for (int i = 0; i < m; i++) { auto [b, a] = P[i]; if (now > a) continue; now = b; ans--; } cout << ans << '\n'; } int main() { ios_base::sync_with_stdio(0), cin.tie(0); #ifdef LOCAL int T; cin >> T; for (int tc = 1; tc <= T; tc++) { cout << "Case" << tc << ":" << '\n'; solve(); } #else solve(); #endif return 0; }