//  (: --Saurabh Mishra-- :) //

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,n) for(ll i=0;i<n;i++)
#define loopn(i,j,n) for(ll i=j;i<n;i++)
#define m_arr(arr, n) vector<ll>arr(n)
#define m_arre(arr) vector<ll>arr
#define m_set(sat) set<ll>sat
#define ppn(name) pair<ll,ll>name
#define pp pair<ll,ll>
#define sort_all(arr) sort(arr.begin(), arr.end())
#define pi 3.141592653589793238
#define mod 1000000007
#define inf 1000000000000000000

ll gcd(ll a, ll b){if(a==0)return b;if(b==0)return a;return gcd(b%a, a);}

ll power(ll a, ll b)
{
    ll res=1;
    while(b>0)
    {
        if(b%2!=0)
            res = (res*1ll*a);
        b/=2;
        a=(a*1ll*a);
    }

    return res;
}

ll fact(ll n)
{
    ll res=1;
    while(n>1)
    {
        res = (res*1ll*n)%mod;
        n--;
    }
    return res;
}

ll ncr(ll n, ll r)
{
    ll num = fact(n);
    ll denum = fact(n-r);
    denum = (denum*1ll*fact(r))%mod;
    denum = power(denum, mod-2);
    num = (num * 1ll * denum)%mod;
    return num;
}

void solve()
{
    ll n;
    cin>>n;
    ll maxx = inf;
    ll cnt=0;
    for(int i=0;i<61;i++)
    {
        ll x = power(2, i);
        cnt = n%x + n/x + i;
        if(maxx>cnt)
            maxx = cnt;
    }

    cout<<maxx<<endl;
    return;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //ll t;cin>>t;while(t--)
    solve();
    return 0;
}

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
char In[1 << 20], *ss = In, *tt = In;
#define getchar() (ss == tt && (tt = (ss = In) + fread(In, 1, 1 << 20, stdin), ss == tt) ? EOF : *ss++)
ll read() {
	ll x = 0, f = 1; char ch = getchar();
	for(; ch < '0' || ch > '9'; ch = getchar()) if(ch == '-') f = -1;
	for(; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + int(ch - '0');
	return x * f;
}
const ll INF = 0x3f3f3f3f3f3f3f3fll;
ll N;
ll ans;
int main() {
	N = read(); ans = INF;
	for(int k = 0; (1ll << k) <= N; k++)
		ans = min(ans, k + (N >> k) + (N & ((1ll << k) - 1)));
	printf("%lld\n", ans);
	return 0;
}
