#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;





int main(){
    ll n,m;
    cin>>n>>m;
    if(m==0){cout<<n+1<<endl; return 0;}
    vector<pll> a(m);
    for(auto &I:a){cin>>I.F>>I.S;}
    sort(a.begin(),a.end());
    vector<pll> A;
    A.push_back(a[0]);
    for(int i=1;i<m;i++){
        if(a[i].S>A.back().S){A.push_back(a[i]);}
    }
    vector<vector<ll>> dp(A.size()+1,vector<ll>(A.size()+1,E));
    dp[0][0]=0;
    for(int i=1;i<=A.size();i++){
        for(int t=0;t<i;t++){
            dp[i][t]=dp[i-1][t];
        }
        for(int t=0;t<i;t++){
            dp[i][i]=min(dp[i][i],dp[i-1][t]+(A[i-1].S-A[t].F)*2);
        }
    }
    cout<<dp[A.size()][A.size()]+n+1<<endl;
    
    
    return 0;
}

