#include #include #define rep(i,n) for (int i = 0; i < (n); ++i) using namespace std; using namespace atcoder; using namespace internal; using P = pair; template void sor(vector &ar){sort(ar.begin(),ar.end());} int main(){ int n, m; cin >> n >> m; int ans = n; vector

ar(m); rep(i,m){ int l, r; cin >> l >> r; ar[i] = P(r,l-1); } sor(ar); int t = 0; rep(i,m){ if (t <= ar[i].second){ ans--; t = ar[i].first; } } cout << ans << endl; }