#include<bits/stdc++.h>

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)

using namespace std;

typedef pair<int,int> ii;

int N,m,par[1010];

int find(int x) { 
  if( x == par[x] ) return x;
  return par[x] = find(par[x]);
}

void unit(int x,int y) {
  x = find(x), y = find(y);
  if( x != y ) par[x] = y;
}

int main(){
  cin >> N >> m;
  int cost = N+1,c,d;
  rep(i,N+2) par[i] = i;
  rep(i,m){
    cin >> c >> d;
    REP(j,c,d) unit(j,j+1);
  }
  map<int,int> group;
  REP(i,1,N+1) ++group[find(i)];
  for(map<int,int>::iterator it = group.begin(); it != group.end(); it++ ){
    if( it->second <= 1 ) continue;
    cost += ( it->second - 1 ) * 2;
  }
  cout << cost << endl;
  return 0;
}
/********
 * 1000 *
 ********/
/*********************
 * go on to the next *
 *********************/
/**************
 * thank you! *
 **************/
/**************
 * help me... *
 **************/