#include #define rep(i,n) for(int i = 0; i < (n); i++) using namespace std; typedef long long ll; int main(){ cin.tie(0); ios::sync_with_stdio(0); int N,M; cin >> N >> M; vector> A(M); for(auto &[L, R] : A) cin >> L >> R; sort(A.begin(), A.end(), [](auto I, auto J) { if(I.second == J.second) return I.first < J.first; return I.second < J.second; }); int LAST = -1e9; int ans = 0; for(auto [L, R] : A) { if(LAST < L) { LAST = R; ans++; } } ans = N - ans; cout << ans << endl; }