#include <bits/stdc++.h>

#define vi vector<int>
#define ii pair<int, int>
#define vii vector<ii>
#define vvi vector<vi>
#define vb vector<bool>
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define INF int(1e9)
#define LL long long int 

using namespace std;

set<LL> setter;

LL to_int(string str){
    stringstream ss;
    ss << str;
    LL integer;
    ss >> integer;
    return integer;
}

string shift(string a){
    string b;

    for(int i=1; i<a.size(); i++)
        b+=a[i];
    
    b+='0';

    return b;
}

void solve(){

    queue<string> fila;

    fila.push("0000000000");
    fila.push("0000000001");
    fila.push("0000000002");
    fila.push("0000000003");
    fila.push("0000000004");
    fila.push("0000000005");
    fila.push("0000000006");
    fila.push("0000000007");
    fila.push("0000000008");
    fila.push("0000000009");
    
    for(int i=0; i<=9; i++)
        setter.insert(i);

    while(!fila.empty()){
        string vertex = fila.front();

//        cout << vertex << endl;        
        
        fila.pop();
        int l = vertex[vertex.size()-1]-'0';

        string new_vertex = shift(vertex);
        //cout << new_vertex << " " << vertex << endl;
        for(int j=max(0, l-1); j<=min(9, l+1); j++){
            
            new_vertex[new_vertex.size()-1]=char(j+'0');

            if(new_vertex==vertex)
                continue;
            setter.insert(to_int(new_vertex));
            fila.push(new_vertex);
        }

        if(setter.size()>100003)
            return;
    }
}


int main () {
    ios_base::sync_with_stdio(false);

    solve();

    /*vector<string> arr;

    for(int i=1; i<=9; i++){
        string str;
        str+=char('0'+i);
        arr.pb(str);
    }

    vi first(11, 0); //last value initiated by i
    
    for(int i=1; i<=9; i++)
        first[i] = i-1;


    while(arr.size()<int(5e1)){
        
        for(int i=1; i<=9; i++){
                
                

                //cout << k << endl;

                for(int l = first[i]; l<arr.size(); l++){
                    int v = arr[l][0]-'0';

                    cout << arr[l] << endl;

                    string str = arr[first[i]];
                
                    int k = str[str.size()-1]-'0';

                    int done = 0;

                    if(v!=i)
                        break;

                    for(int j=max(0, k-1); j<=min(9, k+1); j++){
                        //cout << j << endl;
                        
                        string new_str = str;
                        new_str+=char(j+'0');
                    
                        arr.pb(new_str);
                        if(j==max(0, k-1) and done == 0)
                            first[i] = arr.size()-1, done = 1;
                        
                    }
                }
                //cout << arr[first[i]] << " " << first[i] << endl;   
            }
    }

    for(int i=0; i<arr.size(); i++)
        cout << arr[i] << " ";
    cout << endl;
    */
    
    vector<LL> arr;
    
    for(LL  i : setter){
        arr.pb(i);
    }
    int k;


    cin >> k;

    cout << arr[k] << endl;

    return 0;
}

Measured memory_bytes: 9848