#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using ll = long long;
using PAIR = pair<int, int>;
using PAIRLL = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vc = vector<char>;
using vvc = vector<vc>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vll = vector<ll>;
using vvll = vector<vll>;
using Graph = vector<vector<int>>;

int main()
{
  ll B, C, ans = 0;
  cin >> B >> C;
  if (B > 0)
  {
    if(C==1)
    {
      cout << 2 << endl;
      return 0;
    }
    if (B - C / 2 > 0)
    {
      if (C % 2)
        ans += 2 * (C / 2);
      else
      {
        ans += 2 * (C / 2) - 1;
      }
    }
    else
    {
      ans += 2 * B - 1;
    }

    if (C % 2)
    {
      ans += 2 * ((C-1) / 2) + 1;
    }
    else
    {
      ans += 2 * ((C-1) / 2+1);
    }
  }
  else if (B == 0)
  {
    if(C==1)
    {
      cout << 1 << endl;
      return 0;
    }
    if (C % 2)
    {
      cout << 2 * (C / 2) + 1 << endl;
      return 0;
    }
    else
    {
      cout << 2 * (C / 2) << endl;
      return 0;
    }
  }
  else
  {
    if(C==1)
    {
      cout << 2 << endl;
      return 0;
    }
    if (C % 2)
    {
      ans += 2 * (C / 2+1);
    }
    else
    {
      ans += 2 * (C / 2+1) - 1;
    }
    C--;
    B *= -1;
    if (B - C / 2 > 0)
    {
      if(C==1)
      {
        cout << 4 << endl;
        return 0;
      }
      if (C % 2)
        ans += 2 * (C / 2);
      else
      {
        ans += 2 * (C / 2+1) + 1;
      }
    }
    else
    {
      ans += 2 * B - 1;
    }
  }
  cout << ans << endl;
}

#include<bits/stdc++.h>
#define LL long long
#define DB double
#define pb push_back
#define mkp make_pair
#define LB lower_bound
#define UB upper_bound
#define rint register int
#define MS(x,y) memset(x,y,sizeof(x))
#define rep(i,a,b) for(rint i=a,i##end=b;i<=i##end;++i)
#define drep(i,a,b) for(rint i=a,i##end=b;i>=i##end;--i)
#define cms printf("%.2lf\n",(&o2-&o1)/1024.0/1024)
using namespace std;bool o1;
char IO;
inline int Rd(){
	int _s_=0;
	bool _f_=0;
	while(!isdigit(IO=getchar()))
		IO=='-'&&(_f_=1);
	do _s_=(_s_<<1)+(_s_<<3)+(IO^48);
	while(isdigit(IO=getchar()));
	return _f_?-_s_:_s_;
}
const int M=400005;
int n,m,p,t,A[M],B[M],b[M],c[M],f[M],g[M],T,ans;
vector<int>v[M];
bool o2;int main(){
	n=Rd(),m=Rd();
	rep(i,1,m)
		c[++p]=A[i]=Rd(),b[i]=B[++t]=Rd();
	b[++t]=n;
	sort(b+1,b+1+t);
	sort(c+1,c+1+p);
	t=unique(b+1,b+1+t)-b-1;
	p=unique(c+1,c+1+p)-c-1;
	rep(i,1,m){
		A[i]=LB(c+1,c+1+p,A[i])-c;
		B[i]=LB(b+1,b+1+t,B[i])-b;
		v[A[i]].push_back(B[i]);
	}
	f[LB(b+1,b+1+t,n)-b]=1;
	rep(i,1,p){
		rep(j,0,(int)v[i].size()-1){
			int x=v[i][j];
			g[x]=0;
			if(b[x-1]==b[x]-1)
				g[x]|=f[x-1];
			if(b[x+1]==b[x]+1)
				g[x]|=f[x+1];
		}
		rep(j,0,(int)v[i].size()-1){
			int x=v[i][j];
			f[x]=g[x];
		}
	}
	rep(i,1,t)
		ans+=f[i];
	cout<<ans;
	return 0;
}