#include<iostream>             
#include<vector>   
#include<bits/stdc++.h>
#define mod 1000000007
#define pi 3.14159265358979
#define  PRE(x,p) cout<<setprecision(x)<<p; 
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define endl "\n"
#define high INT_MAX
#define low INT_MIN
#define ll long long int

using namespace std;


void showa(ll a[],ll n){ for(ll i=1;i<=n;i++) cout<<a[i]<<' ';  cout<<endl;  }
void showv(vector<ll>v){ for(ll i=0;i<v.size();i++) cout<<v[i]<<' '; cout<<endl;}


void solve() 
{ 
   ll n;
   cin>>n;
   ll p=1;
   ll b=0;
   ll ans=high;
   while(p<=n)
   {
     ll a=n/p;
     ll c=n%p;
     p=p*2;
     
     ans=min(ans,a+b+c);
     b++;
   }
   cout<<ans;

}
int main()
{
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// #endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);

ll t=1;
// cin>>t;
for(ll test=1;test<=t;test++)
{
    // cout<<"CASE #"<<test<<": ";
    solve();
}

return 0;
}
#include <bits/stdc++.h>
using namespace std;

int main() {
long long int N;
cin>>N;
long long int a;
long long int b;
long long int c;
long long int z;
vector<long long int> vec(1000);
if(N==1){cout<<1<<endl;}
else {
for(long long int i=0;std::pow(2,i)<N;i++)
{z=std::pow(2,i);
 a=N/z;
 b=i;
 c=N%z;
vec.at(i)=a+b+c;
};
  
sort(vec.begin(), vec.end());
  
for(long long int x=0;x<1000;x++)  
{
if(vec.at(x)!=0){cout<<vec.at(x)<<endl;
                break;}


}  
  
  
}
  
  

}
