#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

struct vw_pair
{
    int v, w;
    vw_pair(int v, int w) : v(v), w(w){};
};

typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef vector<vector<vw_pair>> adj_list;
typedef vector<bool> vb;
typedef int_fast64_t ll;
typedef uint_fast64_t ul;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef priority_queue<int> max_heap_int;
typedef priority_queue<int, vi, greater<>> min_heap_int;

#define isOn(S, j) (S & (1 << j))
#define setBit(S, j) (S |= (1 << j))
#define clearBit(S, j) (S &= ~(1 << j))
#define toggleBit(S, j) (S ^= (1 << j))
#define lowBit(S) (S & (-S))
#define setAll(S, n) (S = (1 << n) - 1)
#define modulo(S, N) ((S) & (N - 1)) // returns S % N, where N is a power of 2
#define isPowerOfTwo(S) (!(S & (S - 1)))
#define nearestPowerOfTwo(S) ((int)pow(2.0, (int)((log((double)S) / log(2.0)) + 0.5)))
#define turnOffLastBit(S) ((S) & (S - 1))
#define turnOnLastZero(S) ((S) | (S + 1))
#define turnOffLastConsecutiveBits(S) ((S) & (S + 1))
#define turnOnLastConsecutiveZeroes(S) ((S) | (S - 1))
#define in_range(lo, hi, x) ((x >= lo && x <= hi))
#define numberOfOnBit(x) __builtin_popcountll(x)
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define forsn(i, x, n) for (int i = x; i < int(n); i++)
double esp = 1e-6;

struct custom_hash
{
    static uint64_t splitmix64(uint64_t x)
    {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const
    {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

// Hash map for long long
gp_hash_table<long long, int, custom_hash> ll_hash_map;
// Simple hash for pair
struct chash
{
    int operator()(ii x) const { return x.first * 31 + x.second; }
};
gp_hash_table<ii, int, chash> pair_hash_map;

typedef tree<
    pair<long long, int>,
    null_type,
    less<pair<long long, int>>,
    rb_tree_tag,
    tree_order_statistics_node_update>
    ordered_set;

typedef tree<
    int,
    null_type,
    less<int>,
    rb_tree_tag,
    tree_order_statistics_node_update>
    int_ordered_set;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;cin >> n;
    if (n <= 9) {cout << n << "\n";return 0;}
    int total_num = 0;
    vs cur_q;
    vi d = {-1,0,1};
    forn(i,9) {
        total_num++;
        cur_q.push_back(to_string(i+1));
    }
    while (total_num < n) {
        vs new_q;
        for(string s:cur_q) {
            char c = s[s.size()-1];
            forn(i,3) if (c + d[i] >= '0' && c+d[i] <= '9') {
                new_q.push_back(s + (char)(c+d[i]));
                total_num++;
                if (total_num == n) {cout << s + (char)(c+d[i]) << "\n";return 0;}
            }
        }
        cur_q = new_q;
    }

    return 0;
}


Measured memory_bytes: 5664