#include int n; bool dp[10001][10001]; int countBit(int x){ int ret = 0; while (x > 0){ if (x & 1)ret++; x >>= 1; } return ret; } void init(){ dp[0][1] = true; for (int i = 0; i < 10001; i++){ for (int j = 1; j <= n; j++){ if (dp[i][j]){ int cnt = countBit(j); if (j + cnt <= n)dp[i + 1][j + cnt] = true; if (j - cnt >= 1)dp[i + 1][j - cnt] = true; } } } } int main(){ std::cin >> n; init(); int ans = -1; for (int i = 10000; i >= 0; i--){ if (dp[i][n])ans = i + 1; } std::cout << ans << std::endl; return 0; }