#include using namespace std; typedef long long ll; const int INF = 1000000000; const ll INFL = 2e18; template bool chmin(T &a, T b){ if (a > b) { a = b; return true;} else return false;} template bool chmax(T &a, T b){ if (a < b) { a = b; return true;} else return false;} int main() { int N,M; cin >> N >> M; vector> LR; for (int i = 0;i < M;i++) { int L,R; cin >> L >> R; LR.push_back({L,R}); } sort(LR.begin(), LR.end()); int cnt = 0; for (int i = 0;i < M;i++) { int l,r; tie(l, r) = LR[i]; int j = i; while (true) { int L,R; tie(L,R) = LR[j]; if (max(l, L) <= min(r, R)) { j++; } else break; } cnt++; i = j - 1; } cout << N - cnt << endl; }