module Main where

import Control.Applicative
import Control.Monad
import Data.List (unfoldr)

func :: Int -> Int -> Int
func d n = sum $ unfoldr f n
  where
    f 0 = Nothing
    f x = Just (r, q)
      where
        (q, r) = x `divMod` d

main :: IO ()
main = do
    n <- readLn :: IO Int
    let as = [x | i <- [1..n], let x = func 6 i + func 9 (n - i)]
    print $ minimum as