class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); int count = 1; int i = 1; while(i != n && i <= 10000) { count++; int move = BitCount(Convert.ToString(i, 2)); if(i < n) { i += move; } else { i -= move; } } if (i == n) { Console.WriteLine(count); } else { Console.WriteLine(-1); } } private static int BitCount(string v) { int count = 0; for (int i = 0; i < v.Length; i++) { if (v[i] == '1') { count++; } } return count; } }