#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
using ll = long long;
using VL=vector<ll>;
typedef pair<int,int> pi;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
const long long INF =  999999999;

int main(){
  ll b,c;
  cin>>b>>c;


  if(b==0){
    cout<<c/2+max(ll(0),ll((c-1)/2))+1<<endl;
  }
  else if(b>0){
     if(-b+((c-1)/2)<b-(c/2)){
      cout<<2*((c-1)/2)+(c/2)+max(ll(((c-2)/2)),ll(0))+2;
    }

    else {
      cout<<2*b+((c-1)/2)+max(ll(0),ll(((c-2)/2)))+1;
    }
  }
  else if(b<0){
    if(b+(c-2)/2<-b-(c-1)/2)cout<<2*((c-1)/2)+(c/2)+max(ll(((c-2)/2)),ll(0))+2<<endl;
    else cout<< -2*b+(c-1)/2+c/2+1 <<endl;
  }
}

#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define REP(i,n) for (int i=0; i<n; i++)
using ll = long long;
using P = pair<int,int>;

pair<long, long> extract(const long&B, const long&C) {
  const auto n = C/2;
  if (C%2) {
    return {-B-n, -B+n};
  } else {
    if (!C) return {B,B};
    return {B-n, B+n-1};
  }
}

int main() {
  long B, C;
  cin >> B >> C;
  const auto [a,b] = extract(B,C);
  const auto [c,d] = extract(B,C-1);
  cout << (b-a+1) + (d-c+1) - max(0l, min(b,d)-max(a,c)+1) << endl;
  return 0;
}
