#include <bits/stdc++.h>
using namespace std;


int main(){
    int n, m;   cin >> n >> m;
    vector<pair<int, int> > edges(m);
    for(auto&[x, y] : edges){
        cin >> x >> y;
        --x, --y;
    }

    sort(edges.begin(), edges.end(), [](auto& l, auto& r){
        return (l.second < r.second);
    });
    int now = 0;
    int ans = 2 * (n - 1);
    for(auto&[x, y] : edges){
        if(now > x){
            continue;
        }
        now = y;
        --ans;
    }
    cout << ans << endl;

    return 0;
}