module Main where

import           Control.Monad
import           Debug.Trace
import qualified Data.Vector.Unboxed           as VU
import           Data.List
import qualified Data.ByteString               as BS
import qualified Data.ByteString.Char8         as BSC8
import           Data.Char
import           Data.Maybe
tuplify2 (x : y : _) = (x, y)
tuplify2 _           = undefined

getVUIntFromInputLineAtBSC8 :: IO (VU.Vector Int)
getVUIntFromInputLineAtBSC8 =
    VU.unfoldr (BSC8.readInt . BSC8.dropWhile isSpace) <$> BSC8.getLine
getVUIntListFromInputLineAtBSC8 =
    VU.unfoldr (BSC8.readInt . BSC8.dropWhile isSpace) <$> BSC8.getLine

readInt = fst . fromJust . BSC8.readInt
readIntTuple = tuplify2 . map readInt . BSC8.words
readIntList = map readInt . BSC8.words

getInt = readInt <$> BSC8.getLine
getIntList = readIntList <$> BSC8.getLine
getIntNList n = map readIntList <$> replicateM (fromIntegral n) BSC8.getLine
getIntMatrix = map readIntList . BSC8.lines <$> BS.getContents
getIntTuple = readIntTuple <$> BSC8.getLine
getIntNTuples n = map readIntTuple <$> replicateM (fromIntegral n) BSC8.getLine
getIntTuples = map readIntTuple . BSC8.lines <$> BSC8.getContents

main :: IO ()
main = do

    aK <- getInt

    let kLen = [1 .. 10 ^ 5]
    print $ makeRunrun 1 aK
--    print  $     scanRunrun [1..]  aK

makeRunrun :: Int -> Int -> Int
makeRunrun k 1 = k
makeRunrun k n =
    let
        digit = getDigit k 0
        num x y = div (mod x (10 ^ (y + 1))) (10 ^ (y))
        sa x y = (num x (y + 1)) - (num x y)
    in  
        --trace (show k) $
        makeRunrun
            (foldl
                (\acc x -> if acc == 0
                    then if x == digit
                        then if num k x == 9
                            then test 1 (x+1)
                            else test ((num k x) + 1) x
                        else if num k x == 9
                            then 0
                            else case sa k x of
                                1  -> hoge k (x + 1) + (test ((num k x) + 1) x)
                                0  -> hoge k (x + 1) + (test ((num k x) + 1) x)
                                -1 -> 0
                    else acc
                )
                0
                [0 .. digit]
            )
            (n - 1)

hoge :: Int -> Int -> Int
hoge x digit = let ret = x - (mod x (10 ^ digit)) in ret
test :: Int -> Int -> Int
test x digit =
    let ret = foldl (\acc y -> acc + (max (x - (digit - y)) 0) * (10 ^ y))
                    0
                    (reverse [0 .. digit])
    in  ret

scanRunrun :: [Int] -> Int -> Int
scanRunrun (x : xs) k = if (judgeRunrun x)
    then if k == 1 then x else scanRunrun xs (k - 1)
    else scanRunrun xs k


judgeRunrun :: Int -> Bool
judgeRunrun x =
    let digit = getDigit x 0
        num x y = div (mod x (10 ^ (y + 1))) (10 ^ (y))
    in  foldl (\acc y -> acc && ((abs ((num x (y + 1)) - (num x y))) <= 1))
              True
              (reverse [0 .. digit - 1])

getDigit x n = let y = (div x 10) in if y == 0 then n else getDigit y (n + 1)
