import std.algorithm, std.conv, std.range, std.stdio, std.string; import core.bitop; // bit operation void main() { auto n = readln.chomp.to!int; auto dp = new int[](n + 1); dp[1] = 1; auto cont = true; for (auto c = 1; cont; ++c) { cont = false; foreach (i; iota(1, n)) { if (dp[i] == c) { auto e = i.popcnt; if (i - e >= 1 && dp[i - e] == 0) { dp[i - e] = c + 1; cont = true; } if (i + e <= n && dp[i + e] == 0) { dp[i + e] = c + 1; cont = true; } } } } auto r = dp[n]; writeln(r == 0 ? -1 : r); }