#include using namespace std; using ll = long long; #define rep(i, s, e) for (int i = (int)(s); i < (int)(e); ++i) #define all(a) (a).begin(),(a).end() int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); int N, M; cin >> N >> M; vector> seg(M); rep(i, 0, M) cin >> seg[i].second >> seg[i].first; sort(all(seg)); int ans = 0; int now = 0; rep(i, 0, M) { if (now < seg[i].second) { ++ans; now = seg[i].first; } } cout << N - ans << '\n'; }