#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long
#define pb(a) push_back(a)
#define arr(a) new ll int[a]
#define INF 100000000000000000
#define MOD 1000000007
#define MOD1 998244353
#define arr1(a) new arra[a]
#define str(a) new string[a]
#define all(arr,n,a) for(ll int i=0;i<=n;i++)arr[i]=a
#define mp(a,b) make_pair(a,b)
//const int N = 1000008,p=31;
//ll int pw[N],inv_pw[N],hash2[N+1],hash1[N+1],pw1[N],inv_pw1[N],hash1r[N+1],hash2r[N+1];
////ll fact[N];
////void factorial(){
////    fact[0] = fact[1] = 1;
////    for(ll i = 2; i < N; i++)
////        fact[i] = (fact[i-1] * i) % MOD;
////}
// ll power(ll a, ll b, ll mod){
// 	ll x = 1, y = a;
// 	while (b > 0){
// 		if (b%2){
// 			x = (x*y)%mod;
// 		}
// 		y = (y*y)%mod;
// 		b /= 2;
// 	}
// 	return x%mod;
// }
//ll modular_inverse(ll n, ll mod){
//	return power(n, mod-2, mod);
//}
//void precal()
//{
//    pw[0]=1;
//    pw1[0]=1;
//    inv_pw1[0]=1;
//    inv_pw[0]=1;
//    ll int temp=modular_inverse(p,MOD),temp1=modular_inverse(p,MOD1);
//    for(ll int i=1;i<N;i++)
//    {
//        pw[i]=(pw[i-1]*p)%MOD;
//        pw1[i]=(pw1[i-1]*p)%MOD1;
//        inv_pw1[i]=(inv_pw1[i-1]*temp1)%MOD1;
//        inv_pw[i]=(inv_pw[i-1]*temp)%MOD;
//    }
//}
//void build(string& s,ll int hash1[],ll int pw[],ll int mod)
//{
//    ll int n=s.size();
//    for(ll int i=1;i<=n;i++)
//    {
//        hash1[i]=(hash1[i-1]+(pw[i-1]*(s[i-1]-'a'+1))%mod)%mod;
//    }
//}
//ll int get_hash(ll int hash1[],ll int inv_pw[],ll int mod,ll int l,ll int r)
//{
//    if(l>r)return 0;
//    ll int res=(hash1[r]-hash1[l-1]+mod)%mod;
//    res=(res*inv_pw[l-1])%mod;
//    return res;
//}
//ll nCr(ll n, ll k, ll mod){
//	return (fact[n]*((modular_inverse(fact[k],MOD)*modular_inverse(fact[n-k],MOD))%mod))%mod;
//}

//struct arra{
//    ll int l,r,s,num;
//}arr[300009];
//bool comp(struct arra a,struct arra b)
//{
//    return a.d<b.d;
//}
//bool comp1(pair<ll int,ll int>p1,pair<ll int,ll int>p2)
//{
//    return p1.first>p2.second;
//}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll b,c,t1;
    unsigned ll res=1;
    cin>>b>>c;
    if(b>0)
    {
        if(c%2==0)
        {
            t1=c/2;
            if(t1<=b)
            {
                res+=2*t1-1;
            }
            else{
                res+=2*b-1;
            }
            c--;
            res++;
            t1=c/2;
            res+=2*t1;
        }
        else{
            t1=c/2;
            if(t1<=b-1)res+=2*t1;
            else if(t1==b)res+=2*t1-1;
            else res+=2*b-1;
            c--;
            res++;
            t1=c/2;
            if(t1>0)res+=2*t1-1;
        }
    }
    else if(b==0)
    {
        if(c%2==0)
        {
            t1=c/2;
            if(t1>0)res+=2*t1-1;
        }
        else{
            t1=c/2;
            res+=2*t1;
        }
    }
    else{
        if(c%2==0)
        {
            t1=c/2;
            if(t1>0)res+=2*t1-1;
            c--;
            res++;
            t1=c/2;
            b=abs(b);
            if(t1<=b-1)res+=2*t1;
            else if(t1==b)res+=2*t1-1;
            else res+=2*b-1;
        }
        else{
            t1=c/2;
            res+=2*t1;
            c--;
            res++;
            t1=c/2;
            b=abs(b);
            if(t1<=b)
            {
                if(t1>0)res+=2*t1-1;
            }
            else{
                res+=2*b-1;
            }
        }
    }
    cout<<res;
    return 0;
}

//#include "input.h"
//#include "output.h"
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")


#define NDEBUG
NDEBUG


#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cstring>
#include <cmath>
#include <functional>
#include <numeric>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <memory>
#include <queue>
#include <random>


using namespace std;

template<class T>
using vec = std::vector<T>;


#define FOR(i, n) for (int i = 0; i < (n); ++i)


#define all(c) c.begin(), c.end()


// TC_REMOVE_BEGIN
/// caide keep
bool __hack = std::ios::sync_with_stdio(false);
/// caide keep
auto __hack1 = cin.tie(nullptr);
// TC_REMOVE_END


// Section with adoption of array and vector algorithms.


//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//
//template <class T> using StdTree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;


//bool __hack = std::ios::sync_with_stdio(false);
//auto __hack1 = cin.tie(nullptr);

struct Input {

    Input(istream &in) : in(&in) {}

    template<class T>
    T next() const {
        T x;
        *in >> x;
        return x;
    }

    int ni() const {
        return next<int>();
    }

    
    template<class T>
    vec<T> nVec(int n) const {
        vec<T> v(n);
        for (int i = 0; i < n; ++i) {
            v[i] = next<T>();
        }
        return v;
    }

    vec<int> nvi(int n) const {
        return nVec<int>(n);
    }

    
    istream *in;
};

Input in(cin);


class Output {

private:
ostream *out;

template<typename T>
void printSingle(const T &value) {
    *out << value;
}


public:
Output(ostream &out) : out(&out) {}


inline void print() {}

template<typename T, typename...Ts>
inline void print(const T &f, const Ts&... args) {
    printSingle(f);
    if (sizeof...(args) != 0) {
        *out << ' ';
        print(args...);
    }
}

template<typename...Ts>
inline void println(const Ts&... args) {
    print(args...);
    (*out) << '\n';
}

template<typename...Ts>
inline void operator() (const Ts&... args) {
    println(args...);
}


};

Output out(cout);


namespace template_util {
    

    constexpr int bytecount(uint64_t x) {
        return x ? 1 + bytecount(x >> 8) : 0;
    }

    template<int N>
    struct bytetype {
        
    };

    
    /// caide keep
    template<uint64_t N>
    struct minimal_uint : bytetype<bytecount(N)> {
    };
}


template<typename T> static constexpr T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }


// m must be positive


//template <class T>
//T gcd(T a, T b) {
//    return b == 0 ? a : gcd(b, a % b);
//}

//TODO extended gcd


// MD implementation of factorials and binomial


// TODO(alf): Tests


//
//int64_t lcm(const vector<int64_t>& a) {
//    int64_t res = a[0];
//    for (int i = 1; i < (int)a.size(); ++i) {
//        int64_t g = gcd(res, a[i]);
//        res *= a[i];
//        res /= g;
//    }
//    return res;
//}
//
//int64_t lcm(int64_t a, int64_t b) {
//    return (a * b / gcd(a, b));
//}


// Algorithms


void solve(istream& inStream, ostream& outStream) {
    in = Input(inStream);
    out = Output(outStream);
    auto n = in.ni();
    auto a = in.nvi(n);
    sort(all(a));
    int x = a[0];
    FOR(i, n) x = gcd(x, a[i]);
    out(x);
}

//#include <fstream>


int main() {
//  ifstream fin("input.txt");
//  ofstream fout("output.txt");
//    Input in(in);
//    Output out(out);
    solve(cin, cout);
//  solve(fin, fout);
    return 0;
}

