#include using namespace std; int ret = -1; int n; map check; void calc(int cur,int cnt){ if(cur == n){ ret = cnt; } check[cur] = cnt; int num = 0; int tmp = cur; while(tmp > 0){ if(tmp % 2 == 1)num++; tmp /= 2; } if(cur + num <= n){ if(check[cur+num] == 0 || check[cur+num] > cnt+1) calc(cur+num,cnt+1); } if(cur - num >= 1){ if(check[cur-num] == 0 || check[cur-num] > cnt+1) calc(cur-num,cnt+1); } } int main(){ cin >> n; calc(1,1); cout << ret << endl; }