#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define each(e, v) for(auto &e: v)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) (int)x.size()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int MOD = 1000000007;
//const int MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

struct io_setup{
    io_setup(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout << fixed << setprecision(15);
    }
} io_setup;

int main(){
    ll B, K; cin >> B >> K;

    if(K == 1) {cout << (B == 0? 1 : 2) << '\n'; return 0;}

    B = -B;
    vector<pll> P;

    P.eb(B, B+K/2+1);
    P.eb(-B-(K-1)/2, -B+1);
    P.eb(-B, -B+(K-1)/2+1);
    P.eb(B-(K-2)/2, B+1);

    sort(all(P));
    ll R = -INF*2;
    ll ans = 0;
    each(e, P){
        ll a = e.first, b = e.second;
        chmax(a, R), chmax(b, R);
        ans += b-a;
        chmax(R, b);
    }

    cout << ans << '\n';
}
#include<bits/stdc++.h>
using namespace std;

long long b,c,ans;

int main(){

	ios::sync_with_stdio(false);
	cin.tie(0);

	cin>>b>>c;
	
	if(b<0){
		ans+=min((c-1)/2,-b-1);
		
		if(c>=2)
		ans+=min((c-2)/2,-b-1);
		
		ans+=c/2+1;
		
		ans+=(c-1)/2+1;
	
		if(b<=(c-1)/2)ans++;
	}else{
		ans+=min(c/2+1,b);
		
		if(b>0)
		ans+=min((c-1)/2,b-1);
		
		if(b!=0){
			ans+=(c-1)/2+1;
			
			if(c>=2)
			ans+=(c-2)/2;
			
			if(b<=c/2)ans++;
		}else{
			ans+=c/2+1;
			
			if(c>=2)
			ans+=(c-1)/2;
		}
	}
	cout<<ans<<"\n";

	return 0;
}
