using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace YukiCoder { class Program { static int[] bitCnt = new int[] { 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4 }; static int[] pnStep; static int nMax; static int pnBitN(int ni) { return bitCnt[ni % 16] + bitCnt[ni / 16 % 16] + bitCnt[ni / 16 / 16 % 16] + bitCnt[ni / 16 / 16 / 16 % 16]; } static int zzz(int ns, int ni) { if (ni < 1 || ni > nMax) return nMax; if (ni == nMax) return 1; if (ns >= pnStep[ni]) return nMax; pnStep[ni] = ns; int n = pnBitN(ni); int na = zzz(ns + 1, ni + n); int nb = zzz(ns + 1, ni - n); return (na < nb ? na : nb) + 1; } static void Main(string[] args) { nMax = int.Parse(Console.ReadLine()); pnStep = (new Int32[nMax]).Select(s => nMax).ToArray(); int n = zzz(1, 1); if (n >= nMax) n = -1; Console.WriteLine(n); Console.ReadLine(); } } }