//GOD PLEASE HELP ME ,GOD PLEASE HELP ME , GOD PLEASE HELP ME
//Name Rishiraj Kalita
// sc id : 1912041

#include<bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x)    scanf("%d",&x)
#define sl(x)    scanf("%lld",&x)
#define ss(s)    scanf("%s",s)
#define pi(x)    printf("%d\n",x)
#define pl(x)    printf("%lld\n",x)
#define ps(s)    printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define deb3(x, y, z) cout << #x << "=" << x << "," << #y << "=" << y <<","<< #z << "=" << z << endl
#define debv(v) for(auto x:v) cout<<x<<" "
#define debg(g,n) for(int i=1;i<=n;i++){cout<<i<<"--->";for(auto x:g[i]){cout<<x<<" ";}cout<<"\n";}
#define clrg(g,n) for(int i=0;i<=n;i++) g[i].clear();
#define pb push_back
#define mp make_pair
#define e endl
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define inf 9000000000000000000
typedef pair<int, int>    pii;
typedef pair<ll, ll>    pl;
typedef vector<int>        vi;
typedef vector<ll>        vl;
typedef vector<pii>        vpii;
typedef vector<pl>        vpl;
typedef vector<vi>        vvi;
typedef vector<vl>        vvl;
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
    uniform_int_distribution<int> uid(0,lim-1);
    return uid(rang);
}
int mpow(int base, int exp);
void ipgraph(int n, int m);
void dfs(int u, int par);

const int mod = 1000000007;
const int N = 3e5, M = N;
//=======================

vi g[N];
int a[N];
vpl v;


void solve() {
    ll i, j, n,k,data,m,f=1;
    cin>>n;
    //deb(n);
    unsigned ll ans=inf;
    data= log(n)/log(2);
    for(i=0;i<=data+10;i++)
    {
        unsigned ll x=pow(2,i);
        unsigned ll y=n/x;
        unsigned ll z=n-(x*y);
        //deb3(i,y,z);
        ans=min(ans,i+y+z);
        if(y==0)
        {
            break;
        }
    }
    cout<<ans<<"\n";


  }

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());

    int t = 1;
    //cin >> t;
    while(t--) {
      solve();
    }

    return 0;
}

int mpow(int base, int exp) {
  base %= mod;
  int result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((ll)result * base) % mod;
    base = ((ll)base * base) % mod;
    exp >>= 1;
  }
  return result;
}

void ipgraph(int n, int m){
    int i, u, v;
    while(m--){
        cin>>u>>v;
   // u--, v--;
        g[u].pb(v);
        g[v].pb(u);
    }
}

void dfs(int u, int par){
    for(int v:g[u]){
        if (v == par) continue;
        dfs(v, u);
    }
}




#include <bits/stdc++.h>

using namespace std;

struct cake {
    int a;
    int b;
    int c;
};

int fact(int n) {
    if (n <= 0) {
        return 1;
    }
    return n * fact(n-1);
}

void solve() {
    long long n, m;
    cin >> n;
    cin >> m;
    /*
    vector<cake> v;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            for (int k = 1; k <= n; k++) {
                cake c;
                c.a = i;
                c.b = j;
                c.c = k;
                v.push_back(c);
            }
        }
    }
    sort(v.begin(), v.end(), [](const cake & x, const cake & y) {
        if (x.a + x.b + x.c == y.a + y.b + y.c) {
            if (x.a == y.a) {
                return x.b < y.b;
            }
            return x.a < y.a;
        }
        return x.a + x.b + x.c < y.a + y.b + y.c;
    });

    map<int, int> dupa;
    for (cake & c : v) {
        dupa[c.a+c.b+c.c]++;
        //cout << c.a+c.b+c.c << ": " << c.a << " " << c.b << " " << c.c << endl;
    }
    */
    for (long long k = 0; k <= 3*n-3; k++) {
        long long sum = k+3;
        long long f;
        if (k < n) {
            f = (k+2) * (k+1) / 2;
        } else if (k < 2*n) {
            f = (9*n-3*n*n+6*k*n-6*k-2*k*k-4)/2;
        } else {
            f = (3*n-k-1) * (3*n-k-2) / 2;
        }
        //cout << sum << " " << dupa[sum] << " " << f << endl;
        if (m <= f) {
            for (long long a = 1; a <= n; a++) {
                long long rest = sum - a;
                if (rest >= 2 && rest <= 2 * n) {
                    long long mn = max(1LL, rest - n);
                    long long mx = min(rest - 1, n);
                    long long cnt = mx - mn + 1;
                    if (m <= cnt) {
                        for (long long b = 1; b <= n; b++) {
                            long long c = rest - b;
                            if (c >= 1 && c <= n) {
                                m--;
                                if (m == 0) {
                                    cout << a << " " << b << " " << c << endl;
                                    return;
                                }
                            }
                        }
                    } else {
                        m -= cnt;
                    }
                }
            }
            break;
        } else {
            m -= f;
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed;
    cout.precision(12);

    int T = 1;
    //cin >> T;
    for (int t = 0; t < T; t++) {
        solve();
    }

    return 0;
}

