// #undef _GLIBCXX_DEBUG
// #define NDEBUG
#include <bits/extc++.h>
using i64 = int_fast64_t;
using namespace std;

int main() {
  i64 x, y;
  cin >> x >> y;
  unordered_set<i64> usd;
  priority_queue<pair<i64, i64>, vector<pair<i64, i64>>, greater<>> q;
  q.emplace(0, y);
  i64 ans = 1e18;
  while (!q.empty()) {
    auto [c, z] = q.top();
    q.pop();
    if (usd.count(z)) continue;
    usd.emplace(z);
    ans = min(ans, abs(z - x) + c);
    if (!(z % 2)) {
      q.emplace(c + 1, z / 2);
    } else if (z > 1) {
      q.emplace(c + 2, (z + 1) / 2);
      q.emplace(c + 2, (z - 1) / 2);
    }
  }
  cout << ans << "\n";
}

#include <iostream>
using namespace std;
 
typedef long long ll;
 
#define min(x,y) ((x)<(y)?(x):(y))
#define max(x,y) ((x)<(y)?(y):(x))
 
ll comb(ll n, ll k){
    if (k == 0 || k == n) return 1;
    if (k == 1 || k == n-1) return n;
    return comb(n-1,k)+comb(n-1,k-1);
}
 
int main(){
    ll n,k;cin >> n >> k;--k;
    for(ll xyz=3;xyz<=3*n;++xyz){
        if(xyz <= n+1){
            ll s = (xyz-1)*(xyz-2)/2;
            if(s <= k){
                k -= s;
                continue;
            }
            for(ll x=1;x<=xyz-2;++x){
                ll c = xyz-1-x;
                if(c <= k){
                    k -= c;
                    continue;
                }
                ll y=1+k;
                cout << x << " " << y << " " << (xyz-x-y) << "\n";
                return 0;
            }
        }else if(xyz < 2*n+1){
            ll s = (3*n-xyz+2)*(xyz-n-1)/2;
            if(s <= k){
                k -= s;
            }else{
                for(ll x=1;x<=xyz-n-1;++x){
                    ll c = 2*n-xyz+1+x;
                    if(c <= k){
                        k -= c;
                        continue;
                    }
                    ll y=xyz-n-x+k;
                    cout << x << " " << y << " " << (xyz-x-y) << "\n";
                    return 0;
                }
            }
            s = (xyz-2)*(2*n-xyz+1)/2;
            if(s <= k){
                k -= s;
                continue;
            }
            for(ll x=xyz-n;x<=n;++x){
                ll c = xyz-1-x;
                if(c <= k){
                    k -= c;
                    continue;
                }
                ll y=1+k;
                cout << x << " " << y << " " << (xyz-x-y) << "\n";
                return 0;
            }
        }else{
            ll s = (3*n-xyz+2)*(3*n-xyz+1)/2;
            if(s <= k){
                k -= s;
                continue;
            }
            for(ll x=xyz-2*n;x<=n;++x){
                ll c = 2*n-xyz+1+x;
                if(c <= k){
                    k -= c;
                    continue;
                }
                ll y=xyz-n-x+k;
                cout << x << " " << y << " " << (xyz-x-y) << "\n";
                return 0;
            }
        }
    }
    return 0;
}
