#include using namespace std; using ll = long long int; using iPair = pair; using lPair = pair; using ivector = vector; using lvector = vector; using istack = stack; using iqueue = queue; using ivv = vector>; using lvv = vector>; const int INF = 0x3f3f3f3f; const ll LINF = 0x3f3f3f3f3f3f3f3f; vector dir = {{1,0}, {-1,0}, {0,1}, {0,-1}}; #define dump(x) cout << #x << " = " << (x) << endl #define ALL(x) begin(x),end(x) #define rep(i,s,e) for(ll i=(s), i_stop=(e); i=i_stop; --i) #define range(i,s,n) for(ll i=(s), i_stop=(s)+(n); ii_stop; --i) #define foreach(x,container) for(auto &&x:container) template bool chmax(T& a, S b) {b = (T)b; if(a bool chmin(T& a, S b) {b = (T)b; if(a>b) {a=b;return true;} return false;} template void printArr(vector &arr){ for(auto &x:arr) {cout << x << " ";} cout << endl; } // =====================================================> bool compare(const lPair &a, const lPair &b) { if(a.second == b.second) return a.first < b.first; return a.second < b.second; } void solve() { ll n,m; cin>>n>>m; vector vec; range(i,1,m) {ll x,y; cin>>x>>y; vec.emplace_back(x, y);} sort(vec.begin(), vec.end(), compare); ll t = 0; ll ans = 0; for(ll i = 0; i < m; ++i) { if(vec[i].first > t) { t = vec[i].second; ++ans; } } cout << n-ans << endl; } int main(){ ios::sync_with_stdio(false); cin.tie(0); solve(); return 0; }