import java.util.*;
import java.lang.*;
import java.io.*;
public class Main
{
int[] x = new int[1000001];
public int operations(int n)
{
x[1] = 0;
for (int i = 2; i <= n; i++)
{
x[i] = x[i-1] + 1;
if (i%2 == 0)
{
x
[i
] = Math.
min(x
[i
], x
[i
/2] + 1); }
if (i%3 == 0)
{
x
[i
] = Math.
min(x
[i
], x
[i
/3] + 1); }
}
return x[n];
}
public static void main
(String[] args
) {
Scanner in
= new Scanner
(System.
in); Main x = new Main();
while (in.hasNextInt())
{
int n = in.nextInt();
System.
out.
println(x.
operations(n
)); }
}
}
aW1wb3J0IGphdmEudXRpbC4qOwppbXBvcnQgamF2YS5sYW5nLio7CmltcG9ydCBqYXZhLmlvLio7CgpwdWJsaWMgY2xhc3MgTWFpbgp7CglpbnRbXSB4ID0gbmV3IGludFsxMDAwMDAxXTsKCQoJcHVibGljIGludCBvcGVyYXRpb25zKGludCBuKQoJewoJCXhbMV0gPSAwOwoJCWZvciAoaW50IGkgPSAyOyBpIDw9IG47IGkrKykKCQl7CgkJCXhbaV0gPSB4W2ktMV0gKyAxOwoJCQlpZiAoaSUyID09IDApCgkJCXsKCQkJCXhbaV0gPSBNYXRoLm1pbih4W2ldLCB4W2kvMl0gKyAxKTsKCQkJfQoJCQlpZiAoaSUzID09IDApCgkJCXsKCQkJCXhbaV0gPSBNYXRoLm1pbih4W2ldLCB4W2kvM10gKyAxKTsKCQkJfQoJCX0KCQlyZXR1cm4geFtuXTsKCX0KCgkKCXB1YmxpYyBzdGF0aWMgdm9pZCBtYWluIChTdHJpbmdbXSBhcmdzKQoJewoJCVNjYW5uZXIgaW4gPSBuZXcgU2Nhbm5lcihTeXN0ZW0uaW4pOwoJCU1haW4geCA9IG5ldyBNYWluKCk7CgkJd2hpbGUgKGluLmhhc05leHRJbnQoKSkKCQl7CgkJCWludCBuID0gaW4ubmV4dEludCgpOwoJCQlTeXN0ZW0ub3V0LnByaW50bG4oeC5vcGVyYXRpb25zKG4pKTsKCQl9Cgl9Cn0=