import java.math.BigInteger;
import java.util.*;

public class SolutionIvan {
    public static void main(String[] args) throws Exception {
        new SolutionIvan().run();
    }
    void run() throws Exception {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] z = new int[n + 1];
        z[0] = 0;
        z[1] = 1;
        for (int i = 2; i <= n; ++i) {
            z[i] = Math.min(z[i - 1], z[i / 2 + i % 2]) + 1;
        }
        System.out.println(z[n]);
    }
}
