import           Control.Monad
import           Data.Maybe
import qualified Data.ByteString.Char8 as BS
import qualified Data.Sequence as Seq

readInt = fst . fromJust . BS.readInt
getInt = readInt <$> BS.getLine

main = do
  k <- getInt

  let q = Seq.fromList [1..9]

      nextLL q = let x Seq.:< q1 = Seq.viewl q
                     d = x `mod` 10
                     x0 = x * 10  
                     q2 = if d == 0 then q1 else q1 Seq.|> x0 + (d-1)
                     q3 = q2 Seq.|> x0 + d
                     q4 = if d == 9 then q3 else q3 Seq.|> x0 + (d+1)
                 in (x, q4)

      solve n x q | n == 0 = x
                  | otherwise = solve (n-1) x' q'
        where (x', q') = nextLL q

  print $ solve k 0 q