#include<bits/stdc++.h>
//#include <atcoder/all>

#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define ALL(a)  (a).begin(),(a).end()
#define pb push_back
#define fi first
#define se second
#define sz(x) ((int)x.size())
 
using namespace std;
//using namespace atcoder;
using ld = long double;
using ll = long long;
using P = pair<ll, ll>;
 
template<typename T> bool chmin(T& a, const T& b) { if(a > b){ a = b; return 1;} return 0; }
template<typename T> bool chmax(T& a, const T& b) { if(a < b){ a = b; return 1;} return 0; }

const ll ZER = 0;
const ll MOD = 998244353;
const ll INF = 1e18;

//bit全探索
vector<ll>bitSearch(int bit,int n){
    vector<ll>S;
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    // S.push_back(1e9);
    return S;
}

//最大公約数
ll gcd(ll a, ll b){
    if(a % b == 0)return b;
    else return gcd(b, a % b);
}

int main(){
    int n;
    cin >> n;
    vector<int> x(n);
    rep(i, n)cin >> x[i];
    vector<int> A{2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47};
    int siz = sz(A);
    ll res = 1e18;
    for(int bit = 0; bit < (1 << siz); bit++){
        auto S = bitSearch(bit, siz);
        ll y = 1;
        for(auto s : S)y *= A[s];
        // cout << y << endl;
        bool f = true;
        rep(i, n){
            if(gcd(x[i], y) == 1)f = false;
        }
        if(f)chmin(res, y);
    }
    cout << res << endl;
}
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
double pi = acos(-1);
#define tezi        ios_base::sync_with_stdio(false);\
                    cin.tie(0);\
                    cout.tie(0);
#define FOR(i,a,b)  for(int i=a;i<b;i++)
#define FORR(i,b,a) for(int i=b;i>=a;i--)
#define fill(a,b)   memset(a,b,sizeof(a))
#define _time_      1.0 * clock() / CLOCKS_PER_SEC
#define fi          first
#define se          second
#define mp          make_pair 
#define pb          push_back
#define all(a)      a.begin(),a.end()
#define rev(a)      reverse(all(a))
#define reva(a,n)   reverse(a,a+n)
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

ll powerm(ll a,ll b,ll m){
    if(b==0) return 1;
    if(b&1) return a*powerm(a*a%m,b/2,m)%m;
    return powerm(a*a%m,b/2,m);
}
ll power(ll a,ll b){
    if(b==0) return 1;
    if(b&1) return a*power(a*a,b/2);
    return power(a*a,b/2);
}
ll sqroot(ll number){ 
    ll x = sqrt(number);
    while(x*x<number)x++;
    while(x*x>number)x--;
    return x;
}
ll cbroot(ll number){
    ll x = cbrt(number);
    while(x*x*x<number)x++;
    while(x*x*x>number)x--;
    return x;
}

const int maxn=1e5+5;
//bool prime[maxn];


map<ll,ll> mm;
ll ans=1e18;

void recur(ll x,ll y,ll move){
	if(y<=x){
		ans = min(ans,abs(x-y)+move);
		return;
	}
	if(mm[y] && mm[y]<move)return;
	mm[y] = move;
	ans = min(ans,abs(x-y)+move);
	if(y&1){
		recur(x,y+1,move+1);
		recur(x,y-1,move+1);
	}else{
		recur(x,y/2,move+1);
	}
}

int main(){
    tezi
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //sieve
    //memset(prime,true,sizeof(prime)); 
    //for(ll p=2;p*p<maxn;p++)if(prime[p]==true)for(ll i=p*p;i<maxn;i+=p)prime[i]=false;
    
    ll x,y;
    cin >> x >> y;
    if(x>=y){
    	cout << x-y;
    	return 0;
    }
    recur(x,y,0);
    cout << ans;
    return 0;
}


/*
######                  ####### #     #   ###   #     #    #    ####### ####### ######
#     #  ######  #    # #     # ##   ##    #    ##    #   # #      #    #     # #     #
#     #  #       ##   # #     # # # # #    #    # #   #  #   #     #    #     # #     #
#     #  #####   # #  # #     # #  #  #    #    #  #  # #     #    #    #     # ######
#     #  #       #  # # #     # #     #    #    #   # # #######    #    #     # #   #
#     #  #       #   ## #     # #     #    #    #    ## #     #    #    #     # #    #
######   ######  #    # ####### #     #   ###   #     # #     #    #    ####### #     #
*/