#include <sstream>
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <array>
#include <deque>
#include <numeric>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <list>
#include <cassert>
#include <cmath>
#include <climits>
#include <map>
#include <queue>
#include <functional>
#include <bitset>
#include <cassert>
using namespace std;
using ll = int64_t;
#define rep(i, a) for (int i = 0; i < (int)(a); ++i)
#define rep2(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define repr(i, a) for (int i = (int)((a) - 1); i >= 0; --i)
template <class T> using V1 = vector<T>;
template <class T> using V2 = vector<V1<T>>;
template <class T> using V3 = vector<V2<T>>;
template <class T> using V4 = vector<V3<T>>;
template <class T> using V5 = vector<V4<T>>;
template <class T> V1<T> MV1(size_t n1, T init = T()) { return V1<T>(n1, init); }
template <class T> V2<T> MV2(size_t n1, size_t n2, T init = T()) { return V2<T>(n1, MV1(n2, init)); }
template <class T> V3<T> MV3(size_t n1, size_t n2, size_t n3, T init = T()) { return V3<T>(n1, MV2(n2, n3, init)); }
template <class T> V4<T> MV4(size_t n1, size_t n2, size_t n3, size_t n4, T init = T()) { return V4<T>(n1, MV3(n2, n3, n4, init)); }
template <class T> V5<T> MV5(size_t n1, size_t n2, size_t n3, size_t n4, size_t n5, T init = T()) { return V5<T>(n1, MV4(n2, n3, n4, n5, init)); }
struct dstream { ofstream fout; dstream(const char* fname) : fout(fname) {} };
template <typename T> dstream& operator << (dstream& lhs, const T& rhs) { lhs.fout << rhs; cout << rhs; return lhs; }

template <typename T> vector<T> GetDivisors(T n)
{
	vector<T> v;
	for (T i = 1; i * i <= n; ++i) {
		if ((n % i) == 0) {
			v.push_back(i);
			if ((n / i) != i)
				v.push_back(n / i);
		}
	}
	sort(v.begin(), v.end());
	return v;
}

int main()
{
#ifdef ENV_LOCAL
	ifstream fin("input.txt");
	dstream dout("output.txt");
	auto& in = fin;
	auto& out = dout;
#else
	auto& in = cin;
	auto& out = cout; out << "";
#endif

	int A, B;
	in >> A >> B;
	vector<int> ds(200001);
	for (int i = A; i <= B; ++i) {
		auto divs = GetDivisors(i);
		rep(j, divs.size())
			ds[divs[j]]++;
	}
	int vmax = 0;
	rep(i, ds.size()) {
		if (ds[i] >= 2)
			vmax = max(vmax, i);
	}
	cout << vmax;

	return 0;
}

/**
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⡀⠀⠀⠀⠀⢀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⡖⠁⠀⠀⠀⠀⠀⠀⠈⢲⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⣼⡏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢹⣧⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⣸⣿⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⣿⣇⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⣿⣿⡇⠀⢀⣀⣤⣤⣤⣤⣀⡀⠀⢸⣿⣿⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⢻⣿⣿⣔⢿⡿⠟⠛⠛⠻⢿⡿⣢⣿⣿⡟⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⣀⣤⣶⣾⣿⣿⣿⣷⣤⣀⡀⢀⣀⣤⣾⣿⣿⣿⣷⣶⣤⡀⠀⠀⠀⠀
⠀⠀⢠⣾⣿⡿⠿⠿⠿⣿⣿⣿⣿⡿⠏⠻⢿⣿⣿⣿⣿⠿⠿⠿⢿⣿⣷⡀⠀⠀
⠀⢠⡿⠋⠁⠀⠀⢸⣿⡇⠉⠻⣿⠇⠀⠀⠸⣿⡿⠋⢰⣿⡇⠀⠀⠈⠙⢿⡄⠀
⠀⡿⠁⠀⠀⠀⠀⠘⣿⣷⡀⠀⠰⣿⣶⣶⣿⡎⠀⢀⣾⣿⠇⠀⠀⠀⠀⠈⢿⠀
⠀⡇⠀⠀⠀⠀⠀⠀⠹⣿⣷⣄⠀⣿⣿⣿⣿⠀⣠⣾⣿⠏⠀⠀⠀⠀⠀⠀⢸⠀
⠀⠁⠀⠀⠀⠀⠀⠀⠀⠈⠻⢿⢇⣿⣿⣿⣿⡸⣿⠟⠁⠀⠀⠀⠀⠀⠀⠀⠈⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣼⣿⣿⣿⣿⣧⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠐⢤⣀⣀⢀⣀⣠⣴⣿⣿⠿⠋⠙⠿⣿⣿⣦⣄⣀⠀⠀⣀⡠⠂⠀⠀⠀
⠀⠀⠀⠀⠀⠈⠉⠛⠛⠛⠛⠉⠀⠀⠀⠀⠀⠈⠉⠛⠛⠛⠛⠋⠁⠀⠀
 *    author:  Daredevil666
 *    institution: IIT Patna
**/
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define nl cout<<"\n";
#define ll long long int
#define F(i,a,b) for(i=a;i<b;i++)
#define IOS ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
const double PI = 3.14159265358979323846264338327950288419716939937510582097494459230781641;
const ll M=1e16;
const ll MAXN=200200;
ll i,j,mask;
void solve()
{
   ll x,y;
   cin>>x>>y;
   if(x>=y)
   {
       cout<<x-y;
       return ;
   }
   queue<ll> q;
   q.push(y);
   ll lvl=-1;
   ll ans=y-x;
   set<ll> st;
   st.insert(y);
   while(!q.empty())
   {
       lvl++;
       if(lvl>=ans)break;
       ll s=q.size();
       F(i,0,s)
       {
           ll p=q.front();
           q.pop();
           if(p<=x)
           {
               ans=min(ans,lvl+x-p);
           }
           else
           {
               ans=min(ans,lvl+p-x);
               if(p%2)
               {
                   if(st.count(p+1)==0)
                   {st.insert(p+1);q.push(p+1);}
                   if(st.count(p-1)==0)
                   {st.insert(p-1);q.push(p-1);}
               }
               else
               {
                   if(st.count(p/2)==0)
                   {st.insert(p/2);q.push(p/2);}
               }
           }
       }
   }
   cout<<ans;
}
int main()
{
IOS
/*#ifndef ONLINE_JUDGE
   freopen("input.txt","r",stdin);
   freopen("output.txt","w",stdout);
#*/
/*ll t,test;
cin>>test;
F(t,1,test+1)
{
    //cout<<"Case #"<<t<<": ";
    solve();
    nl
}*/
solve();
return 0;
}
