digit :: Int -> Int
digit n = length $ takeWhile (<= n) ( iterate (*10) 1 )


-- 各桁ペアごとのルンルン性リストを返す
checkDigits :: Int -> [Bool]
checkDigits n = reverse [ abs (a - b) <= 1 | (a,b) <- zip ms (tail ms) ]
    where
        ms = take (digit n) . map (`mod` 10) $ iterate (`div` 10) n


-- ダメな桁ペアの一番最初のもの
-- 例：97123 -> 1,2番目の要素について、 (|9-7| <= 1) を満たさないから
--     この場合 2番目の要素を +1, つまり +10^3 = 10^(digit - 2(=badIndex)) 
--     したい。よって戻り値 2。
badIndex :: [Bool] -> Int
badIndex ns = (2+) . length $ takeWhile (== True) ns


isLun :: Int -> Bool
isLun n = and $ checkDigits n


bitLun :: Int -> Int
bitLun n 
    | isLun n   = 1 
    | otherwise = 0


floorNum :: Int -> Int -> Int
floorNum n i  = n - mod n (10^i)


searchK :: Int -> Int
searchK n = f' (n+1) 0
    where
    f' 0 count = count - 1
    f' k count = f' (k - bitLun count) next
        where
        next
            | isLun count = count + 1
            | otherwise   = floorNum (count + (10 ^ pow)) pow
        pow = digit count - badIndex (checkDigits count)


main :: IO ()
main = do
    k <- read <$> getLine :: IO Int
    print $ searchK k
    