#include<bits/stdc++.h>
#define For(i,a,b) for(register int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(register int i=(a);i>=(b);--i)
#define int long long
using namespace std;
inline int read()
{
    char c=getchar();int x=0;bool f=0;
    for(;!isdigit(c);c=getchar())f^=!(c^45);
    for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
    if(f)x=-x;return x;
}
#define fi first
#define se second
#define mkp make_pair
#define pb push_back
typedef pair<int,int>pii;
#define maxn 200005
int b,c;
inline int cross(int l1,int r1,int l2,int r2){
	if(l1>l2)swap(l1,l2),swap(r1,r2);
	//cout<<l1<<' '<<r1<<' '<<l2<<' '<<r2<<endl; 
	if(l2<=r1)return max(r1,r2)-l1+1;
	return r2-l2+1+r1-l1+1;
}
signed main()
{
	b=read(),c=read();
	if(b>=0){
		int l1=-b-(c-1)/2,r1=-b+(c-1)/2;
		int l2=b-c/2,r2=b;
		if(c>2)r2=max(r2,b+(c-2)/2);
		cout<<cross(l1,r1,l2,r2); 
	}else{
		int l1=b-c/2,r1=b+(c-2)/2;
		int l2=-b-(c-1)/2,r2=-b+(c-1)/2;
		cout<<cross(l1,r2,l2,r2); 
	}
	return 0;
}
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <utility>
#include <cmath>
#include <unordered_map>
#include <math.h>
#define mod 1000000007
#define PI 3.141592653589

typedef long long ll;
const long long INF=1e18;
const long long inf=1e5 + 5;

using namespace std;

ll power(ll a, ll b) 
{   ll result =1;
    while(b)
    {   if(b%2) result=(result*a)%mod;
        a=(a*a)%mod;
        b/=2;
    }
    return result;
}
void solve()
{
    ll n,i,j;
    ll sum=0;
    cin>>n;
    vector <ll> a(n);
    for(auto &x : a)
    {
        cin>>x;
        sum+=x;
    }
    //Bottom up approach check whether given sum can be made or not
    bool dp[n+1][sum+1];

    for(i=0;i<=n;i++) //if sum is 0 answer is true
    {
        dp[i][0]=true;
    }
    for(i=1;i<=sum;i++) //if sum>0 and set is empty
    {
        dp[0][i]=false;
    }
    //bottom up approach
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=sum;j++)
        {
            if(dp[i-1][j])
            {
                dp[i][j]=true;
            }
            else
            {
                if(j>=a[i-1] && dp[i-1][j-a[i-1]])
                {
                    dp[i][j]=true;
                }
                else
                {
                    dp[i][j]=false;
                }
            }
        }
    }
    ll init=(sum+1)/2;
    for(i=init;i<=sum;i++)
    {
        if(dp[n][i])
        {
            cout<<i;
            return;
        }
    }

}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif 

    int t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}

