using System; using System.Collections.Generic; public class yukicoder{ public static int move(int n) { string s = Convert.ToString(n, 2); int m = 0; foreach(char c in s) { if(char.IsNumber(c)) { m += int.Parse(c.ToString()); } } return m; } public static void Main(){ int goal = int.Parse(Console.ReadLine()); int[] board = new int[goal]; List usedcell = new List(); for(int i = 0; i < board.Length; i++) { board[i] = i + 1; } int now = 1; while(true) { usedcell.Add(now); if(now == goal) { Console.WriteLine(usedcell.Count); break; } if((now + move(board[now - 1])) > goal) { now -= move(board[now - 1]); if(usedcell.Contains(now)) { Console.WriteLine(-1); break; } } else { now += move(board[now - 1]); } } } }