#include using namespace std; #define rep(i, n) for (int i = 0; i < (n); ++i) using ll = long long; using ull = unsigned long long; int main() { cin.tie(nullptr)->sync_with_stdio(false); int n, m; cin >> n >> m; vector> v(m); rep(i, m) cin >> v[i].first >> v[i].second; sort(v.begin(), v.end(), [](auto x, auto y) { return tie(x.second, x.first) < tie(y.second, y.first); }); int ans = n; int cur = 0; rep(i, m) { if (v[i].first > cur) ans--, cur = v[i].second; } cout << ans << '\n'; return 0; }