#include<bits/stdc++.h>

using namespace std;
#define FOR(i,bg,ed) for(int i=bg;i<ed;i++)
#define REP(i,n) FOR(i,0,n)
template<typename T>
bool chmax(T& l,T r){
    bool ret = l<r;
    if(l<r)l=r;
    return ret;
}
template<typename T>
bool chmin(T& l,T r){
    bool ret = l>r;
    if(l>r)l=r;
    return ret;
}
typedef long long LL;
typedef vector<LL> V;
string s;
const LL inf = 1e14;
const int empty = 1e9;
int main(){
    int n,m;
    cin>>n>>m;
    vector<int> p(n+2,-1);
    REP(i,m){
        int c,d;
        cin>>c>>d;
        chmax(p[c],d);
    }
    LL res= n+1;
    int bg = empty;
    int ed = -1;
    REP(i,n+1){
        if(p[i+1]>=i+1){
            chmin(bg,i+1);
            chmax(ed,p[i+1]);
        }
        if(bg!=empty&&ed<=i+1){
            res+=2*(i+1-bg);
            ed=-1;
            bg = empty;
        }
    }
    cout<<res<<endl;
    return 0;
}