#include<bits/stdc++.h>
using namespace std;
using ll = long long;
main(){
ll n = 1e18;
ll x = 1;
ll m = 0 , t = 0;
ll a = 0 , b = 0;
for(ll i = 0 ; ; i ++){
if((1ll << i) == n){
m = t = i;
break;
}
if((1ll << i) > n){
m = i - 1;
t = i;
break;
}
}
a = (1ll << m);
b = (1ll << t);
ll ans = min(m + (n - a) , t + (b - n));
printf("%lld\n" , ans);
return 0;
}
CiNpbmNsdWRlPGJpdHMvc3RkYysrLmg+CgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKdXNpbmcgbGwgPSBsb25nIGxvbmc7CgoKbWFpbigpewoKCiAgICBsbCBuID0gMWUxODsKICAgIGxsIHggPSAxOwoKICAgIGxsIG0gPSAwICwgdCA9IDA7CiAgICBsbCBhID0gMCAsIGIgPSAwOwoKICAgIGZvcihsbCBpID0gMCA7IDsgaSArKyl7CiAgICAgICAgICAgIGlmKCgxbGwgPDwgaSkgPT0gbil7CiAgICAgICAgICAgICAgICAgICAgbSA9IHQgPSBpOwogICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmKCgxbGwgPDwgaSkgPiBuKXsKICAgICAgICAgICAgICAgICAgICBtID0gaSAtIDE7CiAgICAgICAgICAgICAgICAgICAgdCA9IGk7CiAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIH0KICAgIH0KCiAgICBhID0gKDFsbCA8PCBtKTsKICAgIGIgPSAoMWxsIDw8IHQpOwoKCiAgICBsbCBhbnMgPSBtaW4obSArIChuIC0gYSkgLCB0ICsgKGIgLSBuKSk7CiAgICBwcmludGYoIiVsbGRcbiIgLCBhbnMpOwoKICAgIHJldHVybiAwOwp9Cgo=