#include using namespace std; #ifdef _RUTHEN #include "debug.hpp" #else #define show(...) true #endif using ll = long long; #define rep(i, n) for (int i = 0; i < (n); i++) template using V = vector; int main() { ios::sync_with_stdio(false); cin.tie(0); int N, M; cin >> N >> M; V> RL(M); rep(i, M) cin >> RL[i].second >> RL[i].first; sort(RL.begin(), RL.end()); int ans = 0, rm = 0; for (auto [r, l] : RL) { if (rm <= l) { rm = r; ans++; } } ll res = 2 * (N - 1) - ans; cout << res << '\n'; return 0; }