#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template <class T = int>T in(){
    T x;
    cin >> x;
    return (x);
}

template<class T> inline void chmin(T& a, T b){
    if (a > b){
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b){
    if (a < b){
        a = b;
    }
}

/* modつき二分累乗法 */
ll modpow(ll a, ll b) {
    ll res = 1;
    for (a = a; b; a = a * a , b >>= 1){
        if (b & 1) res = res * a;
    }
    return res;
}


signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    int K = in();
    vector<vector<int>> A(10,vector<int>(10));
    int count = 0;
    bool bre = 0;
    int c,d;
    REP(i,10){
        REP(l,10){
            if(i == 0){
                A[i][l] = 1;
            }else if(l == 0){
                A[i][l] = A[i-1][l] + A[i-1][l+1];
            }else if(l == 9){
                A[i][l] = A[i-1][l] + A[i-1][l-1];
            }else{
                A[i][l] = A[i-1][l] + A[i-1][l-1] + A[i-1][l+1];
            }
            if(l == 0){
            }else if(count + A[i][l] >= K){
                bre = 1;
                c = i;
                d = l;
            }
            if(bre)break;
            if(l != 0)count += A[i][l];
        }
        if(bre)break;
    }
    ll start = modpow(10,c)*d;
    int e = 0;
    if(c >= 9){
        if(d == 0){
            if(count + A[8][0] >= K){
                e = 0;
            }else{
                e = 1;
                count += A[8][0];
            }
        }else{
            if(count + A[8][d-1] >=K){
                e = d-1;
            }else if(count + A[8][d-1] + A[8][d] >=K){
                e = d;
                count += A[8][d-1];
            }else{
                e = d + 1;
                count += A[8][d-1] + A[8][d];
            }
        }
        d = e;
    }
    start += e*modpow(10,8);
    int f = 0;
    if(c >= 8){
        if(d == 0){
            if(count + A[7][0] >= K){
                f = 0;
            }else{
                f = 1;
                count += A[7][0];
            }
        }else if(d == 9){
            if(count + A[7][d-1] >=K){
                f = d-1;
            }else{
                f = d;
                count += A[7][d-1];
            }
        }else{
            if(count + A[7][d-1] >=K){
                f = d-1;
            }else if(count + A[7][d-1] + A[7][d] >=K){
                f = d;
                count += A[7][d-1];
            }else{
                f = d + 1;
                count += A[7][d-1] + A[7][d];
            }
        }
        d = f;
    }
    start += f*modpow(10,7);
    int g = 0;
    if(c >= 7){
        if(d == 0){
            if(count + A[6][0] >= K){
                g = 0;
            }else{
                g = 1;
                count += A[6][0];
            }
        }else if(d == 9){
            if(count + A[6][d-1] >=K){
                g = d-1;
            }else{
                g = d;
                count += A[6][d-1];
            }
        }else{
            if(count + A[6][d-1] >=K){
                g = d-1;
            }else if(count + A[6][d-1] + A[6][d] >=K){
                g = d;
                count += A[6][d-1];
            }else{
                g = d + 1;
                count += A[6][d-1] + A[6][d];
            }
        }
    }
    start += g*modpow(10,6);
    for(;;start++){
        string l = to_string(start);
        bool ko = 1;
        REP(k,l.size()-1){
            if(abs(l[k] - l[k+1]) > 1){
                ko = 0;
                break;
            }
        }
        if(ko)count++;
        if(count == K)break;
    }
    cout  << start << "\n";
}

Measured memory_bytes: 256