// Author :
// Date :
// Problem:
// Solution:
// Comment:

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cmath>
#include <cstring>

#define pp push
#define pb push_back
#define mp make_pair
#define xx first
#define yy second

using namespace std;

void play(int n , int c){
    int mas[1005]={0};
    int lock[1005] = {0};
    int cur = 0;
    int left = 0;
    int maxx = -1;
    int minn = -1;
    int step = 0;
    
    int a,b;
    for(int i = 0 ; i < c ; i++){
        cin >> a >> b;
        if(lock[a] < b){
            lock[a] = b;
        }
    }
    
    //cout << cur << endl;
    
    while(cur < n+1){
        //cout << cur << endl;
        if(lock[cur] != 0 && lock[cur] > maxx) maxx = lock[cur];
        if(lock[cur] != 0 && minn == -1) minn = cur;
        
        if(cur == maxx){
            while(cur > minn){
                
                cur--;
                lock[cur] = 0;
                //cout << "minn " << minn << endl;
                //cout << cur << endl;
                step++;
            }
            maxx = -1;
            minn = -1;
        }
        cur++;
        step++;
    }

    cout << step << endl;
}
int main(){
    int a,b;
    
    cin >> a >> b;
    
    play(a,b);
    
    #ifdef GEREL
        for(;;);
    #endif

    return 0;
}