#include<bits/stdc++.h>
using namespace std;

#define int long long
#define pb push_back 
#define pf push_front 
#define mp make_pair
#define fr first
#define sc second
#define Rep(i, n) for ( int i = 0 ; i < (n); i++ )
#define All(v) v.begin(), v.end()

typedef pair<int, int> Pii; typedef pair<int, Pii> Pip;
const int INF = 1107110711071107;

int N, m;
vector<Pii> d;
unordered_map<int, int> dp[1001][1001];

int dfs(int pre, int now, int n) {
  if ( n == m ) {
    return (now-pre + (N+1)-pre);
  }
  if ( dp[pre][now][n] > 0 ) return dp[pre][now][n];

  int ret = dfs(min(pre, d[n].sc), d[n].fr, n+1) + (d[n].fr-now);
  ret = min(ret, dfs(d[n].sc, d[n].fr, n+1) + (now-pre + d[n].fr-pre));

  return dp[pre][now][n] = ret;
}

signed main() {
  cin >> N >> m;

  Rep(i, m) {
    int c, b;
    cin >> c >> b;
    d.pb(Pii(b, c));    
  }

  sort(All(d));

  if ( m == 0 ) cout << N+1 << endl;
  else cout << dfs(d[0].sc, d[0].fr, 1) + d[0].fr << endl;
}