#define rep(i,n) for(int i=0;i<(int)(n);i++) #define ALL(v) v.begin(),v.end() typedef long long ll; #include using namespace std; int main(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); ll n,m; cin>>n>>m; vector A(m),B(m); rep(i,m) cin>>A[i]>>B[i]; vector> P(m); rep(i,m) P[i]={B[i],A[i]}; sort(ALL(P)); int now=0,cnt=0; rep(i,m){ if(P[i].second>=now){ cnt++; now=P[i].first; } } cout<<2*(n-1)-cnt<