#include<bits/stdc++.h>
using namespace std;
#define int ll
#define ll long long
#define db double
#define rep(i,be,en) for(int i=be;i<=en;i++)
const int INF = 0x3f3f3f3f;
const ll inf=0x3f3f3f3f3f3f3f3f;
//const double pi=acos(-1);
const int mod=1e9+7;
#define eps 1e-8
#define zero(x) (((x)>0?(x):-(x))<eps)
using namespace std;
const int N=1e5+7;
const int M=1e6+7;

inline int read(){
    char c=getchar();int x=0,f=1;
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    return x*f;
}

int T,n,m,fl;


signed main(){
	n=read();
	int x=1,a=0,b=0,c=0,ans,aa,bb,cc;
	a=n/x;
	ans=a;aa=a;bb=0;cc=0;
	while(x*2<=n){
		b++;
		x*=2;
		a=n/x;
		c=n%x;
		if(a+b+c<ans){
			ans=a+b+c;
			aa=a;bb=b;cc=c;
		}
	}
	
	printf("%lld\n",ans,aa,bb,cc);
	
}

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

int main() {
  long long n;
  cin>>n;
  long long ans =1000000000000000000;
  for(int i=0;i<61;i++){
    long long b=i;
    long long a=n/(1LL<<i);
    long long c=n-a*(1LL<<i);
    ans = min(ans,a+b+c);
  }
  cout << ans << endl;
}
