#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fo(i,a,b) for(int i = a; i<b ; i++)
#define FIO ios_base::sync_with_stdio(false);   cin.tie(NULL);   cout.tie(NULL);
#define pb push_back
#define M 1000000007
int mod(int x){
return ((x%M + M)%M);
}
int add(int a,int b){
return mod(mod(a)+mod(b));
// return a*1ll + b*1ll;
}
int mul(int a,int b){
return mod(mod(a)*mod(b));
// return a*b*1ll;
}
// ****************************************************************************
pair<int,int> dp[2][100001];
int n;
int a[100001];
int res;
pair<int,int> rec(int f,int i){
    
    if(i==n)
    return {0ll,1ll};
    // if(dp[f][i]!={-1ll,-1ll})
    // return dp[f][i];
    auto p = dp[f][i];
    if(p.first!=-1)
    return p;
    // int temp;
    if(i==0){
        int x = rec(0,i+1).first;
        int y = rec(0,i+1).second;
        // return {add(a,mul(a[i]))}
        // return add({x,mul(a[i],y)});
        return {add(x,mul(a[i],y)),y};
    }
    int ans =0;
    if(f==0){
        // now we can put both
        // int temp = rec(0,i+1);
        // int tempp = rec(1,i+1);
        // res=add(res,mul(a[i],temp));
        // res=add(res,-mul(a[i],tempp));
        // // int x = mul(a[i],tempp);
        // // res = (res-x)%M;
        // // res=add(res,-x);
        // // res = mod(mod(res)-x);
        // return dp[f][i]=add(temp,tempp);
        int ans;
        int x1 = rec(0,i+1).first;
        int y1 = rec(0,i+1).second;
        ans = add(x1,mul(a[i],y1));
       int  x2 = rec(1,i+1).first;
        int y2 = rec(1,i+1).second;
        ans=add(ans,x2);
        ans=add(ans,-mul(a[i],y2));
        return dp[f][i]={ans,add(y1,y2)};
    }
    else{
        // now i can only put +here
        // ans=mul(a[i],rec(0,i+1));
        // int temp = rec(0,i+1);
        // res=add(res,mul(a[i],temp));
        // return dp[f][i]=temp;
        int x = rec(0,i+1).first;
        int y = rec(0,i+1).second;
        return dp[f][i]={add(x,mul(a[i],y)),y};
        // return dp[f][i]={add}
    }
    // cout<<ans<<endl;
    return {1,1};
    
}

void solve(){
    cin>>n;
    fo(i,0,n)
    cin>>a[i];
    // memset(dp,-1,sizeof dp);
    // cout<<rec(0,0);
    fo(i,0,2){
        fo(j,0,n)
        dp[i][j]={-1,-1};
    }
    // cout<<rec(0,0).first;
    auto p = rec(0,0);
    cout<<p.first;
    // cout<<mod(res);
    // cout<<res;
}
signed main()
{
FIO
int t;
t=1;
// cin>>t;
while(t--)
{
solve();
}
}
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<utility>
#include<set>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

struct fast_io {
	fast_io(){
		std::cin.tie(nullptr);
		std::ios::sync_with_stdio(false);
	};
} fio;

set<int> s;

void rec(int B, int C){
    
    if(C < 0) return ;
    
    s.insert(B);
    
    rec(-B, C - 1);
    rec(B-1, C - 2);
}

int solve(int B, int C){
    s.clear();
    
    rec(B, C);
    
    cout<<"ANS = "<<endl;
    cout<<s.size()<<endl<<endl;
    
    for(int y : s){
        // cout<<y<<endl;
        cout<<y<<" ";
    }
    cout<<endl;
}


int solve2(int B, int C){
    
    int a = 0, b = 0, c = 0;
    int D, E, F, G;
    int res = 0;
    int maxi = 0;
    
    a = (C - 1)/ 2;
    b = max((C - 2)/2, 0ll);
    c =(C + 0)/2;
    
    if(B == 0) {
        cout<<C<<endl;
        return 0;
    } else if(B < 0) {
        D = -B + a;
        E = -B - a;
        F = B + b;
        G = B - c;
    } else {
        D = B + b;
        E = B - c;
        F = -B + a;
        G = -B - a;
    }
    
    
    // cout<<D<<" "<<E<<" "<<F<<" "<<G<<endl;
    // cout<<G<<" "<<F<<" "<<E<<" "<<D<<endl;
    res += F - G + 1;
    res += max(0ll, D - max(E-1, F));
    
    // cout<<a<<" "<<b<<endl;
    
    cout<<res<<endl;
    
    return res;
}


signed main(){
	cout<<fixed<<setprecision(10);
	
	int B, C;
	
    cin>>B>>C;
    
    // solve(B, C);
    
    solve2(B, C);
	
	return 0;
}