import java.util.* fun main(args: Array){ val boxCount = readLine()!!.toInt() val box = arrayOfNulls(boxCount+1) val move = box.indices.map { it.toString(2).count { it == '1' }} val que = LinkedList() que.push(Task(1, 1)) while (que.isNotEmpty()) { val task = que.pop() if(task.pos <= 0) { continue } if(task.pos > boxCount) { continue } if(box[task.pos] == null || box[task.pos]!! > task.step) { box[task.pos] = task.step } else { continue } que.push(Task(task.pos + move[task.pos], task.step + 1)) que.push(Task(task.pos - move[task.pos], task.step + 1)) } box[boxCount]?.also { println(box[boxCount]) } ?: run { println(-1) } } class Task(val pos:Int, val step:Int)