#include #include #include #include using namespace std; using ll = long long; using ull = unsigned long long; #define rep(i,n) for(int i=0; i<(n); i++) int N,M; vector> X; int main(){ cin >> N >> M; X.resize(M); rep(i,M) cin >> X[i].first >> X[i].second; sort(X.begin(),X.end()); int ans = N; int fastR = N; for(auto x : X){ if(x.first > fastR){ ans--; fastR = x.second; } else{ fastR = min(fastR,x.second); } } ans--; cout << ans << "\n"; return 0; } struct ios_do_not_sync{ ios_do_not_sync(){ ios::sync_with_stdio(false); cin.tie(nullptr); } } ios_do_not_sync_inst;