import java.util import scala.collection.mutable object Main { def main(args: Array[String]): Unit = { val sc = new java.util.Scanner(System.in) val i: Int = sc.nextInt() val queue = new util.ArrayDeque[Point]() val ans = mutable.Set(Point(-1, -1, mutable.Set(-1))) queue.add(Point(1, 1, mutable.Set(1))) while (!queue.isEmpty) { val p = queue.poll() if (p.now == i) { ans += p } else if (1 <= p.now && p.now <= i) { val newPoint: Int = p.now.toBinaryString.replaceAll("0", "").length if (!p.history(p.now + newPoint)) { queue.add(Point(p.count + 1, p.now + newPoint, p.history += p.now)) } if (!p.history(p.now - newPoint)) { queue.add(Point(p.count + 1, p.now - newPoint, p.history += p.now)) } } } val max: Int = ans.seq.map(p => p.count).max printf(max.toString) } } case class Point(count: Int, now: Int, history: mutable.Set[Int])