#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;



int main(){
    ll K;
    cin >> K;
    vector<ll> lunlun(0);
    vector<vector<ll> > keta(10,vector<ll>(0));
    for(ll i = 1; i <= 9; i++){
        keta[0].push_back(i);
        lunlun.push_back(i);
    }
    for(ll i = 0; i <= 8; i++){
        ll len_keta = keta[i].size();
        for(ll j = 0; j < len_keta; j++){
            if (keta[i][j] == 323456676){
                break;
            }
            ll num = keta[i][j] % 10;
            switch(num){
                case 0:
                    keta[i + 1].push_back(keta[i][j] * 10);
                    lunlun.push_back(keta[i][j] * 10);
                    keta[i + 1].push_back(keta[i][j] * 10 + 1);
                    lunlun.push_back(keta[i][j] * 10 + 1);
                    break;
                case 1:
                    keta[i + 1].push_back(keta[i][j] * 10);
                    lunlun.push_back(keta[i][j] * 10);
                    keta[i + 1].push_back(keta[i][j] * 10 + 1);
                    lunlun.push_back(keta[i][j] * 10 + 1);
                    keta[i + 1].push_back(keta[i][j] * 10 + 2);
                    lunlun.push_back(keta[i][j] * 10 + 2);
                    break;
                case 2:
                    keta[i + 1].push_back(keta[i][j] * 10 + 1);
                    lunlun.push_back(keta[i][j] * 10 + 1);
                    keta[i + 1].push_back(keta[i][j] * 10 + 2);
                    lunlun.push_back(keta[i][j] * 10 + 2);
                    keta[i + 1].push_back(keta[i][j] * 10 + 3);
                    lunlun.push_back(keta[i][j] * 10 + 3);
                    break;
                case 3:
                    keta[i + 1].push_back(keta[i][j] * 10 + 2);
                    lunlun.push_back(keta[i][j] * 10 + 2);
                    keta[i + 1].push_back(keta[i][j] * 10 + 3);
                    lunlun.push_back(keta[i][j] * 10 + 3);
                    keta[i + 1].push_back(keta[i][j] * 10 + 4);
                    lunlun.push_back(keta[i][j] * 10 + 4);
                    break;
                case 4:
                    keta[i + 1].push_back(keta[i][j] * 10 + 3);
                    lunlun.push_back(keta[i][j] * 10 + 3);
                    keta[i + 1].push_back(keta[i][j] * 10 + 4);
                    lunlun.push_back(keta[i][j] * 10 + 4);
                    keta[i + 1].push_back(keta[i][j] * 10 + 5);
                    lunlun.push_back(keta[i][j] * 10 + 5);
                    break;
                case 5:
                    keta[i + 1].push_back(keta[i][j] * 10 + 4);
                    lunlun.push_back(keta[i][j] * 10 + 4);
                    keta[i + 1].push_back(keta[i][j] * 10 + 5);
                    lunlun.push_back(keta[i][j] * 10 + 5);
                    keta[i + 1].push_back(keta[i][j] * 10 + 6);
                    lunlun.push_back(keta[i][j] * 10 + 6);
                    break;
                case 6:
                    keta[i + 1].push_back(keta[i][j] * 10 + 5);
                    lunlun.push_back(keta[i][j] * 10 + 5);
                    keta[i + 1].push_back(keta[i][j] * 10 + 6);
                    lunlun.push_back(keta[i][j] * 10 + 6);
                    keta[i + 1].push_back(keta[i][j] * 10 + 7);
                    lunlun.push_back(keta[i][j] * 10 + 7);
                    break;
                case 7:
                    keta[i + 1].push_back(keta[i][j] * 10 + 6);
                    lunlun.push_back(keta[i][j] * 10 + 6);
                    keta[i + 1].push_back(keta[i][j] * 10 + 7);
                    lunlun.push_back(keta[i][j] * 10 + 7);
                    keta[i + 1].push_back(keta[i][j] * 10 + 8);
                    lunlun.push_back(keta[i][j] * 10 + 8);
                    break;
                case 8:
                    keta[i + 1].push_back(keta[i][j] * 10 + 7);
                    lunlun.push_back(keta[i][j] * 10 + 7);
                    keta[i + 1].push_back(keta[i][j] * 10 + 8);
                    lunlun.push_back(keta[i][j] * 10 + 8);
                    keta[i + 1].push_back(keta[i][j] * 10 + 9);
                    lunlun.push_back(keta[i][j] * 10 + 9);
                    break;
                case 9:
                    keta[i + 1].push_back(keta[i][j] * 10 + 8);
                    lunlun.push_back(keta[i][j] * 10 + 8);
                    keta[i + 1].push_back(keta[i][j] * 10 + 9);
                    lunlun.push_back(keta[i][j] * 10 + 9);
                    break;
                default:
                    break;
            }
        }
    }
    cout << lunlun[K - 1] << endl;
}


Measured memory_bytes: 2296