using System; using System.Linq; using System.Collections.Generic; using System.Text; using static System.Console; using static System.Math; class Program { static int[] dp; static int N = 0; static void Main(string[] args) { N = int.Parse(ReadLine()); dp = Enumerable.Repeat(1000000000, 10001).ToArray(); dp[1] = 1; DFS(1); WriteLine(dp[N] == 1000000000 ? -1 : dp[N]); } static void DFS(int from) { int delta = 0; for (int j = 0; j < 32; j++) if (((from >> j) & 1) == 1) delta++; if(N >= from + delta && dp[from + delta] > dp[from] + 1) { dp[from + delta] = dp[from] + 1; DFS(from + delta); } if(1 <= from - delta && dp[from - delta] > dp[from] + 1) { dp[from - delta] = dp[from] + 1; DFS(from - delta); } } }