#include <bits/stdc++.h>
#define int long long
#define Mid ((l + r) >> 1)
#define lson (rt << 1)
#define rson (rt << 1 | 1)
using namespace std;
int read(){
	char c; int num, f = 1;
	while(c = getchar(),!isdigit(c)) if(c == '-') f = -1; num = c - '0';
	while(c = getchar(), isdigit(c)) num = num * 10 + c - '0';
	return f * num;
}
signed main()
{
	int b = read(), c = read(), ans, minn;
	if(b < 0) ans = c + 1;
	else if(b > 0) {
		if(c <= 2) ans = 2;
		else ans = c;
	} else if(b == 0) {
		ans = c;
	}
	if(b == 0){
		printf("%lld\n", ans);
		return 0;
	}
	if(b < 0) b = -b, c -= 1;
	minn = b - c / 2;
	if(minn <= 0) {
		minn = 1;
		ans++;
	}
	if((b - minn) * 2 < c) ans += (b - minn) * 2;
	else if(b != minn) ans += (b - minn - 1) * 2 + 1;
	printf("%lld\n", ans);
	return 0;
}

#include<cstdio>
#include<set>
#define fo(x,a,b) for(int x=(a),e_=(b);x<=e_;x++)
#define fd(x,a,b) for(int x=(a),e_=(b);x>=e_;x--)
#define fi first
#define se second
#define mp make_pair
#define ww printf

using namespace std;
typedef long long ll;
set<pair<int,int>> s;
int n;

int main(){
	int u,v;
	scanf("%d",&n);
	fo(i,1,n) {
		scanf("%d",&u);
		auto it=s.lower_bound(mp(u,0));
		if(it==s.end() || it->fi!=u) s.insert(mp(u,1));
		else v=it->se, s.erase(it), s.insert(mp(u,v+1));
	}
	while(true){
		auto itl=s.begin(), itr=s.end(); itr--;
		if(itl==itr) break;
		u=itr->fi, v=itr->se;
		u-=itl->fi;
		s.erase(itr);
		
		auto it=s.lower_bound(mp(u,0));
		if(it!=s.end() && it->fi==u) 
			v+=it->se, s.erase(it);
		s.insert(mp(u,v));
	}
	printf("%d",s.begin()->fi);
	return 0;
}
