#include <array>
#include <iostream>
#include <numeric>
#include <stdexcept>
#include <vector>

struct LoopOut : std::exception {
};

int main()
{
    int rest_K;
    std::cin >> rest_K;

    // x桁の、yで始まり、zで終わるルンルン数の個数
    // =table.at(x - 1).at(y).at(z)
    std::vector<std::array<std::array<int, 10>, 10>> table(1);
    for (auto y = 0; y < 10; y++) {
        for (auto z = 0; z < 10; z++) {
            table.front().at(y).at(z) = int{y == z};
        }
    }

    // x桁の、yで始まるルンルン数の個数
    std::vector<std::array<int, 10>> sum_table{{1, 1, 1, 1, 1, 1, 1, 1, 1, 1}};

    int top_order;

    if (rest_K <= 9) {
        top_order = rest_K;
        rest_K = 1;
    } else {
        rest_K -= 9;

        try {
            for (;;) {
                table.emplace_back();
                sum_table.emplace_back();

                for (top_order = 0; top_order < 10; top_order++) {
                    auto const& table_prev = table.at(table.size() - 2).at(top_order);
                    auto& table_con = table.back().at(top_order);
                    auto& sum = sum_table.back().at(top_order);
                    sum = 0;

                    for (auto bottom_order = 0; bottom_order < 10; bottom_order++) {
                        switch (bottom_order) {
                        case 0: {
                            table_con.at(0) = table_prev.at(0)
                                              + table_prev.at(1);
                            break;
                        }

                        case 9: {
                            table_con.at(9) = table_prev.at(8)
                                              + table_prev.at(9);
                            break;
                        }

                        default: {
                            table_con.at(bottom_order) = table_prev.at(bottom_order - 1)
                                                         + table_prev.at(bottom_order)
                                                         + table_prev.at(bottom_order + 1);
                            break;
                        }
                        }

                        sum += table_con.at(bottom_order);
                    }

                    if (top_order != 0) {
                        auto diff = rest_K - sum;
                        if (diff <= 0) {
                            throw LoopOut{};
                        }
                        rest_K = diff;
                    }
                }
            }
        } catch (LoopOut&) {
        }
    }

    // std::cout << table.size() << "桁で" << top_order << "始まり" << std::endl;
    // std::cout << "そんな数は" << std::accumulate(table.back().at(top_order).cbegin(), table.back().at(top_order).cend(), 0) << "個ある" << std::endl;
    // std::cout << "その" << rest_K << "番目" << std::endl;


    std::cout << top_order;
    for (int order_con = table.size() - 2; order_con >= 0; order_con--) {
        top_order = std::max(0, top_order - 1);
        auto num_max = std::min(9, top_order + 2);
        // std::cout << "\t" << top_order << ' ' << num_max << std::endl;

        for (; top_order <= num_max; top_order++) {
            auto diff = rest_K - sum_table.at(order_con).at(top_order);
            // std::cout << "diff: " << diff << std::endl;
            if (diff <= 0) {
                break;
            }
            rest_K = diff;
        }
        std::cout << top_order;
    }
    std::cout << std::endl;
}


Measured memory_bytes: 256