#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

int main(){
  ll b,c;
  cin>>b>>c;
  
  if(b==0) cout<<c<<endl;
  else if(b>0){
    if(c==1) cout<<2<<endl;
    else if(c==2) cout<<3<<endl;
    else cout<<c-1+min(2*b,c)<<endl;
  }
  else{
    if(c==1) cout<<2<<endl;
    else if(c==2) cout<<3<<endl;
    else cout<<c+min(2*(-b),c)<<endl;
  }

  return 0;
}
#include "bits/stdc++.h"
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,a,n) for(int i=n;i>=a;i--)
#define pb push_back
#define mp make_pair
#define FI first
#define SE second
#define maxn 200000
#define mod 1000000007
#define inf 0x3f3f3f3f
template<class T> bool chmax(T &a, const T &b) {if(a<b) {a=b; return 1;} return 0;}
template<class T> bool chmin(T &a, const T &b) {if(b<a) {a=b; return 1;} return 0;}
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef double db;

int main()
{
    ll B,C; scanf("%lld%lld",&B,&C);
    vector<pair<ll,ll>> s;
    s.pb({B-C/2,B});
    s.pb({-B,-B+(C-1)/2});
    s.pb({-B-(C-1)/2,-B});
    if(C>=2) s.pb({B,B+(C-2)/2});
    sort(s.begin(),s.end());
    ll rt=-8e18,ans=0;
    for(auto [l,r]: s)
    {
        if(r>rt)
        {
            if(l>rt) ans+=r-l+1;
            else ans+=r-rt;
            rt=r;
        }
    }
    printf("%lld\n",ans);
    return 0;
}