(* O(n) *)
let n = read_int ()
let dp = Array.make (n + 1) n
let pss = Array.make_matrix 2 7 1
let f j b = for i = 1 to 6 do pss.(j).(i) <- pss.(j).(i - 1) * b done
let _ =
  List.iteri f [6; 9];
  dp.(0) <- 0;
  for i = 1 to n do
    for j = 0 to 1 do
      for k = 0 to 6 do
        if pss.(j).(k) <= i then dp.(i) <- min dp.(i) @@ dp.(i - pss.(j).(k)) + 1 done done done;
  dp.(n) |> Printf.printf "%d\n"