#include #include #include int n; int dp[10001]; const int inf = 100000000; int countBit(int x){ int ret = 0; while (x > 0){ if (x & 1)ret++; x >>= 1; } return ret; } int main(){ std::cerr << "Hello" << std::endl; std::cin >> n; for (int i = 0; i < 10001; i++)dp[i] = inf; dp[1] = 1; for (int i = 0; i < 10001; i++){ for (int j = 1; j <= n; j++){ if (dp[j] == inf)continue; int cnt = countBit(j); if (j + cnt <= n)dp[j + cnt] = std::min(dp[j + cnt], dp[j] + 1); if (j - cnt >= 1)dp[j - cnt] = std::min(dp[j - cnt], dp[j] + 1); } } std::cout << (dp[n] == inf ? -1 : dp[n]) << std::endl; return 0; }