#include int main(void) { int n, i, j = 1, k, current = 1, c2, log[10]={0,0,0,0,0,0,0,0,0,0}; scanf("%d", &n); while (current < n) { c2 = current; i = 0; while(c2) { c2 &= (c2 - 1); i++; } if (current+i <= n) { current += i; } else if (current+i > n) { current -= i; } j++; for (k = 0; k < 10; k++) { if (log[k] == current) { printf("-1\n"); return 0; } } log[j%10] = current; } if (current == n) { printf("%d\n", j); } else { printf("-1\n"); } return 0; }