#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

ll X, Y;
unordered_map<ll, ll> mp;

ll solve(ll y) {
    if(mp.find(y) != mp.end()) return mp[y];
    if (y == 1) return mp[y] = abs(X-y);
    else if (y % 2 == 1) return mp[y] = min(min(solve(y+1)+1, solve(y-1)+1), abs(X-y));
    else return mp[y] = min(abs(X-y), solve(y/2)+1);
}


int main() {
    cin >> X >> Y;
    solve(Y);
    cout << mp[Y] << endl;

    return 0;
}
#include<bits/stdc++.h>
#define faster  ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define ull unsigned long long
#define pb push_back
const double PI = acos(-1.0);
using namespace std;

int main()
{
    faster

    ll n,m;
    cin>>n>>m;

    if(m==0)
    {
        cout<<1<<endl;
        return 0;
    }

    ll a[m];
    for(int i=0; i<m; i++)
        cin>>a[i];

    sort(a,a+m);

    vector<int> v;

    ll mn;

    if(a[0]!=1)
    {
        v.pb(a[0]-1);
    }

    for(int i=1; i<m; i++)
    {
        if(a[i]-(a[i-1]+1)!=0)
            v.pb(a[i]-(a[i-1]+1));
    }

    if(a[m-1]!=n)
    {
        v.pb(n-a[m-1]);
    }

    //cout<<v.size()<<endl;
    if(v.size()==0)
    {
        cout<<0<<endl;
        return 0;
    }

    sort(v.begin(),v.end());

    mn=v[0];

    ll ans=0;

    for(int i=0; i<v.size(); i++)
    {
        //cout<<v[i]<<" ";
        ans=ans+(v[i]/mn);

        if(v[i]%mn!=0)
            ans++;
    }

    cout<<ans<<endl;







    return 0;
}
