import std.stdio, std.string, std.conv;
import std.algorithm, std.array, std.range;
auto solve(string s_){
    immutable K = s_.chomp.to!int();
    if(K<13) return K.to!string();
    string a;
    void add(int i){ a~=(i+'0').to!char(); }
    immutable M=18;
    auto dp = new int[10][M];
    dp[1][]=1;
    auto t=9;
    foreach(i;2..M) foreach(j;0..10){
        auto n=dp[i-1][j];
        if(j>0) n+=dp[i-1][j-1];
        if(j<9) n+=dp[i-1][j+1];
        dp[i][j]=n;
        if(j==0) continue;
        if(t+n<K){
            t+=n;
            continue;
        }
        a.reserve(i);
        add(j);
        auto p=j;
        foreach_reverse(m;1..i){
            foreach(k;max(0,p-1)..min(10,p+2)){
                if(t+dp[m][k]>=K){
                    add(k);
                    p=k;
                    break;
                }
                t+=dp[m][k];
            }
        }
        return a;
    }
    return a;
}
void main(){ for(string s; (s=readln.chomp()).length;) writeln(solve(s)); }