#include #include #include #include using namespace std; typedef pair pii; int n; void bfs(vector &block, int s){ block[s] = 1; queue que; que.push(pii(2, s)); int cnt; while(not que.empty()){ s = que.front().second; cnt = que.front().first; int w = __builtin_popcount(s); que.pop(); if(s - w >= 1 and block[s - w] > cnt){ block[s - w] = cnt; que.push(pii(cnt + 1, s - w)); } if(n >= s + w and block[s + w] > cnt){ block[s + w] = cnt; que.push(pii(cnt + 1, s + w)); } } } int main(){ std::cin >> n; vector block(n + 1, 1e9); bfs(block, 1); if(n == 1)std::cout << 0 << std::endl; else if(block[n] != 1e9)std::cout << block[n] << std::endl; else std::cout << -1 << std::endl; return 0; }