let rec power x n =
  if n <= 0 then 1
  else if n mod 2 = 0 then
    power (x*x) (n/2)
  else
    x * power x (n - 1)
    
let rec loop x m c =
    if x - power c m >= 0 then
      loop x (m+1) c
    else 
      m - 1
let rec subloop x m cnt =
  if x - m*cnt < 0 then
    cnt - 1
  else
    subloop x m (cnt+1)

let () =
  let n = Scanf.scanf "%d\n" (fun x -> x) in
  
  let n9 = loop n 0 9 in
  let n9li = Array.to_list (Array.init (n9+1) (fun x -> power 9 x)) in
  let n6 = loop n  0 6 in
  let n6li = Array.to_list (Array.init (n6+1) (fun x -> power 6 x)) in
  let li =  List.rev (List.sort_uniq (-) (n9li @  n6li )) in
  let  rec iter li sum cnt =
  match li with
  | x::xs -> let a = subloop sum x 0  in
             iter xs (sum - a * x) (cnt + a)
  | [] -> cnt
  in
  let cnt = iter li n 0 in
    
                
             
  
    
  Printf.printf "%d\n" cnt
