import qualified Data.Sequence as S
import qualified Data.Char as C

toInt x = read x :: Int

lst n = map C.digitToInt $ show n
seqLength n = length $ lst n
toIntSeq n = S.fromList $ lst n


lnlnCheck :: [Int] -> S.Seq Int -> Bool
lnlnCheck [_] seq = True
lnlnCheck (x:xs) seq
    |dif == Just 0 = lnlnCheck xs seq
    |dif == Just 1 = lnlnCheck xs seq
    |dif == Just (-1) = lnlnCheck xs seq
    |otherwise = False
        where dif = (-) <$> (seq S.!? x) <*> (seq S.!? (x+1))

lnln n = lnlnCheck [0..(seqLength n - 1)] $ toIntSeq n

lnlnlst :: [Integer]
lnlnlst = filter lnln [1..]

main = do
    k <- toInt <$> getLine
    print $ head $ drop (k-1) lnlnlst