#include using namespace std; int N; int result = INT_MAX; int dp[10000] = {0}; int Bitone(int num){ vector bit; while(num != 0){ bit.push_back(num % 2 + '0'); num /= 2; } int i = 0; for(auto itr = bit.begin(); itr != bit.end(); ++itr) if(*itr == '1') ++i; return i; } void rec(int num = 1, int sum = 1){ if(0 >= num || num > N || result < sum) return; if(num == N){ if(result > sum) result = sum; return; } if(dp[num] != 0 && dp[num] <= sum) return; dp[num] = sum; int x = num + Bitone(num); int y = num - Bitone(num); rec(x, sum + 1); rec(y, sum + 1); return; } int main(void){ cin >> N; rec(); if(result == INT_MAX) cout << -1 << endl; else cout << result << endl; return 0; }