import std.stdio, std.conv, std.string, std.range, std.math, std.bigint, std.algorithm, core.bitop; void main() { auto N = readln.strip.to!int; //auto dice = 1.iota(N + 1).map!(a => iota(a.to!real.log2.floor.to!int+1).map!(i => (a>>i)&1).sum).array; auto dice = 1.iota(N + 1).map!(e => popcnt(e)).array; int dfs(int i, int c) { if (dice[i] == 0) return -1; if (i == N - 1) return c; auto tmp = dice[i]; dice[i] = 0; if (i + tmp >= N) return dfs(i - tmp, c + 1); return dfs(i + tmp, c + 1); } dfs(0, 1).writeln; }