#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <boost/range/adaptors.hpp>
#include <iomanip>
#include <tuple>
#include <numeric>

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

    std::vector<long long> lunlun_numbers;
    for (long long i = 1; i <= 9; ++i) {
        lunlun_numbers.push_back(i);
    }
    int start = 0;
    int goal = lunlun_numbers.size();

    if (K <= lunlun_numbers.size()) {
        std::cout << lunlun_numbers[K - 1] << std::endl;
        return 0;
    }

    for (int i = start; i < goal; ++i) {
        long long last_number = lunlun_numbers[i] % 10;
        if (last_number == 0) {
            lunlun_numbers.push_back(lunlun_numbers[i] * 10);
            lunlun_numbers.push_back(lunlun_numbers[i] * 10 + 1);
        } else if (last_number == 9) {
            lunlun_numbers.push_back(lunlun_numbers[i] * 10 + 8);
            lunlun_numbers.push_back(lunlun_numbers[i] * 10 + 9);
        } else {
            lunlun_numbers.push_back(lunlun_numbers[i] * 10 + last_number - 1);
            lunlun_numbers.push_back(lunlun_numbers[i] * 10 + last_number);
            lunlun_numbers.push_back(lunlun_numbers[i] * 10 + last_number + 1);
        }
    }
    start = goal;
    goal = lunlun_numbers.size();

    if (K <= lunlun_numbers.size()) {
        std::cout << lunlun_numbers[K - 1] << std::endl;
        return 0;
    }

    for (int i = start; i < goal; ++i) {
        long long last_number = lunlun_numbers[i] % 10;
        if (last_number == 0) {
            lunlun_numbers.push_back(lunlun_numbers[i] * 10);
            lunlun_numbers.push_back(lunlun_numbers[i] * 10 + 1);
        } else if (last_number == 9) {
            lunlun_numbers.push_back(lunlun_numbers[i] * 10 + 8);
            lunlun_numbers.push_back(lunlun_numbers[i] * 10 + 9);
        } else {
            lunlun_numbers.push_back(lunlun_numbers[i] * 10 + last_number - 1);
            lunlun_numbers.push_back(lunlun_numbers[i] * 10 + last_number);
            lunlun_numbers.push_back(lunlun_numbers[i] * 10 + last_number + 1);
        }
    }
    start = goal;
    goal = lunlun_numbers.size();

    if (K <= lunlun_numbers.size()) {
        std::cout << lunlun_numbers[K - 1] << std::endl;
        return 0;
    }

    for (int i = start; i < goal; ++i) {
        long long last_number = lunlun_numbers[i] % 10;
        if (last_number == 0) {
            lunlun_numbers.push_back(lunlun_numbers[i] * 10);
            lunlun_numbers.push_back(lunlun_numbers[i] * 10 + 1);
        } else if (last_number == 9) {
            lunlun_numbers.push_back(lunlun_numbers[i] * 10 + 8);
            lunlun_numbers.push_back(lunlun_numbers[i] * 10 + 9);
        } else {
            lunlun_numbers.push_back(lunlun_numbers[i] * 10 + last_number - 1);
            lunlun_numbers.push_back(lunlun_numbers[i] * 10 + last_number);
            lunlun_numbers.push_back(lunlun_numbers[i] * 10 + last_number + 1);
        }
    }
    start = goal;
    goal = lunlun_numbers.size();

    if (K <= lunlun_numbers.size()) {
        std::cout << lunlun_numbers[K - 1] << std::endl;
        return 0;
    }

    for (int i = start; i < goal; ++i) {
        long long last_number = lunlun_numbers[i] % 10;
        if (last_number == 0) {
            lunlun_numbers.push_back(lunlun_numbers[i] * 10);
            lunlun_numbers.push_back(lunlun_numbers[i] * 10 + 1);
        } else if (last_number == 9) {
            lunlun_numbers.push_back(lunlun_numbers[i] * 10 + 8);
            lunlun_numbers.push_back(lunlun_numbers[i] * 10 + 9);
        } else {
            lunlun_numbers.push_back(lunlun_numbers[i] * 10 + last_number - 1);
            lunlun_numbers.push_back(lunlun_numbers[i] * 10 + last_number);
            lunlun_numbers.push_back(lunlun_numbers[i] * 10 + last_number + 1);
        }
    }
    start = goal;
    goal = lunlun_numbers.size();

    if (K <= lunlun_numbers.size()) {
        std::cout << lunlun_numbers[K - 1] << std::endl;
        return 0;
    }


    for (int i = start; i < goal; ++i) {
        long long last_number = lunlun_numbers[i] % 10;
        if (last_number == 0) {
            lunlun_numbers.push_back(lunlun_numbers[i] * 10);
            lunlun_numbers.push_back(lunlun_numbers[i] * 10 + 1);
        } else if (last_number == 9) {
            lunlun_numbers.push_back(lunlun_numbers[i] * 10 + 8);
            lunlun_numbers.push_back(lunlun_numbers[i] * 10 + 9);
        } else {
            lunlun_numbers.push_back(lunlun_numbers[i] * 10 + last_number - 1);
            lunlun_numbers.push_back(lunlun_numbers[i] * 10 + last_number);
            lunlun_numbers.push_back(lunlun_numbers[i] * 10 + last_number + 1);
        }
    }
    start = goal;
    goal = lunlun_numbers.size();

    if (K <= lunlun_numbers.size()) {
        std::cout << lunlun_numbers[K - 1] << std::endl;
        return 0;
    }
    
    for (int i = start; i < goal; ++i) {
        long long last_number = lunlun_numbers[i] % 10;
        if (last_number == 0) {
            lunlun_numbers.push_back(lunlun_numbers[i] * 10);
            lunlun_numbers.push_back(lunlun_numbers[i] * 10 + 1);
        } else if (last_number == 9) {
            lunlun_numbers.push_back(lunlun_numbers[i] * 10 + 8);
            lunlun_numbers.push_back(lunlun_numbers[i] * 10 + 9);
        } else {
            lunlun_numbers.push_back(lunlun_numbers[i] * 10 + last_number - 1);
            lunlun_numbers.push_back(lunlun_numbers[i] * 10 + last_number);
            lunlun_numbers.push_back(lunlun_numbers[i] * 10 + last_number + 1);
        }
    }
    start = goal;
    goal = lunlun_numbers.size();

    if (K <= lunlun_numbers.size()) {
        std::cout << lunlun_numbers[K - 1] << std::endl;
        return 0;
    }
    
    for (int i = start; i < goal; ++i) {
        long long last_number = lunlun_numbers[i] % 10;
        if (last_number == 0) {
            lunlun_numbers.push_back(lunlun_numbers[i] * 10);
            lunlun_numbers.push_back(lunlun_numbers[i] * 10 + 1);
        } else if (last_number == 9) {
            lunlun_numbers.push_back(lunlun_numbers[i] * 10 + 8);
            lunlun_numbers.push_back(lunlun_numbers[i] * 10 + 9);
        } else {
            lunlun_numbers.push_back(lunlun_numbers[i] * 10 + last_number - 1);
            lunlun_numbers.push_back(lunlun_numbers[i] * 10 + last_number);
            lunlun_numbers.push_back(lunlun_numbers[i] * 10 + last_number + 1);
        }
    }
    start = goal;
    goal = lunlun_numbers.size();

    if (K <= lunlun_numbers.size()) {
        std::cout << lunlun_numbers[K - 1] << std::endl;
        return 0;
    }
    
    for (int i = start; i < goal; ++i) {
        long long last_number = lunlun_numbers[i] % 10;
        if (last_number == 0) {
            lunlun_numbers.push_back(lunlun_numbers[i] * 10);
            lunlun_numbers.push_back(lunlun_numbers[i] * 10 + 1);
        } else if (last_number == 9) {
            lunlun_numbers.push_back(lunlun_numbers[i] * 10 + 8);
            lunlun_numbers.push_back(lunlun_numbers[i] * 10 + 9);
        } else {
            lunlun_numbers.push_back(lunlun_numbers[i] * 10 + last_number - 1);
            lunlun_numbers.push_back(lunlun_numbers[i] * 10 + last_number);
            lunlun_numbers.push_back(lunlun_numbers[i] * 10 + last_number + 1);
        }
    }
    start = goal;
    goal = lunlun_numbers.size();

    if (K <= lunlun_numbers.size()) {
        std::cout << lunlun_numbers[K - 1] << std::endl;
        return 0;
    }
    
    for (int i = start; i < goal; ++i) {
        long long last_number = lunlun_numbers[i] % 10;
        if (last_number == 0) {
            lunlun_numbers.push_back(lunlun_numbers[i] * 10);
            lunlun_numbers.push_back(lunlun_numbers[i] * 10 + 1);
        } else if (last_number == 9) {
            lunlun_numbers.push_back(lunlun_numbers[i] * 10 + 8);
            lunlun_numbers.push_back(lunlun_numbers[i] * 10 + 9);
        } else {
            lunlun_numbers.push_back(lunlun_numbers[i] * 10 + last_number - 1);
            lunlun_numbers.push_back(lunlun_numbers[i] * 10 + last_number);
            lunlun_numbers.push_back(lunlun_numbers[i] * 10 + last_number + 1);
        }
    }
    start = goal;
    goal = lunlun_numbers.size();

    if (K <= lunlun_numbers.size()) {
        std::cout << lunlun_numbers[K - 1] << std::endl;
        return 0;
    }
    
    for (int i = start; i < goal; ++i) {
        long long last_number = lunlun_numbers[i] % 10;
        if (last_number == 0) {
            lunlun_numbers.push_back(lunlun_numbers[i] * 10);
            lunlun_numbers.push_back(lunlun_numbers[i] * 10 + 1);
        } else if (last_number == 9) {
            lunlun_numbers.push_back(lunlun_numbers[i] * 10 + 8);
            lunlun_numbers.push_back(lunlun_numbers[i] * 10 + 9);
        } else {
            lunlun_numbers.push_back(lunlun_numbers[i] * 10 + last_number - 1);
            lunlun_numbers.push_back(lunlun_numbers[i] * 10 + last_number);
            lunlun_numbers.push_back(lunlun_numbers[i] * 10 + last_number + 1);
        }
    }
    start = goal;
    goal = lunlun_numbers.size();

    if (K <= lunlun_numbers.size()) {
        std::cout << lunlun_numbers[K - 1] << std::endl;
        return 0;
    }
    return 0;
}

Measured memory_bytes: 2420