#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int dfs(int n, vector<vector<int> >& adj){
	if((int)adj[n].size() == 0) return n;
	int ret=0;
	for(int i=0; i<(int)adj[n].size(); i++){
		ret = max(ret, dfs(adj[n][i], adj));
	}
	adj[n].clear();
	return ret;
}

int main(){
	int n,m;
	cin >> n >> m;
	
	vector<vector<int> > need(n+1);
	for(int i=0; i<m; i++){
		int c,d;
		cin >> c >> d;
		need[c].push_back(d);
	}
	vector<int> c,d;
	for(int i=1; i<=n; i++){
		int top = dfs(i, need);
		if(top != i){
			c.push_back(i);
			d.push_back(top);
		}
	}
	c.push_back(n+1);
	d.push_back(n+1);
	
	int ans = 0;
	int s=c[0], e=d[0];
	for(int i=1; i<(int)c.size(); i++){
		if(c[i] <= e){
			e = max(e, d[i]);
		}else{
			ans += e-s;
			s = c[i];
			e = d[i];
		}
	}
	ans = n +1 +ans*2;
	cout << ans << endl;
	return 0;
}