#include using namespace std; int main(){ long long n; cin >> n; int c = 0; while(n){ if(n & 1){ if((n & 3) == 3 && n > 3) n++; else n--; c++; } else n >>= 1; } cout << c << endl; return 0; }