#include using namespace std; void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); } int main() { fast_io(); int n, m; cin >> n >> m; vector l(m), r(m); for (int i = 0; i < m; i++) { cin >> l[i] >> r[i]; } vector ii(m); iota(ii.begin(), ii.end(), 0); sort(ii.begin(), ii.end(), [&](int i, int j) { return r[i] < r[j]; }); int la = 0, ans = n; for (int i : ii) { if (l[i] > la) { la = r[i]; ans--; } } cout << ans << endl; }