#include #include int N; bool visited[10001]; int memo[10001]; int dfs(int pos){ if(pos < 1 || pos > N){return 1001001001;} if(pos == N){return 1;} if(visited[pos]){return 1001001001;} if(memo[pos] != -1){return memo[pos];} visited[pos] = true; int bc = __builtin_popcount(pos), res = std::min(dfs(pos-bc)+1, dfs(pos+bc)+1); visited[pos] = false; return memo[pos] = res; } int main(int argc, char** argv){ std::cin >> N; std::fill(memo, memo+10001, -1); int res = dfs(1); if(res < 1001001001){ printf("%d\n", res); }else{ puts("-1"); } }