// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

#define rep(i,N) for(int i=0;i<int(N);++i)

#define rep1(i,N) for(int i=1;i<int(N);++i)

#define all(a) (a).begin(),(a).end()

#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }

#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }

#define dump(x) cerr<<#x<<": "<<x<<endl;

#define bit(k) (1LL<<(k))

#define Yes "Yes"

#define No "No"

#define YES "YES"

#define NO "NO"

typedef long long ll;

template <class T> using vec = vector<T>;

template <class T> using vvec = vector<vec<T>>;

template< typename T1, typename T2 >

ostream &operator<<(ostream &os, const pair< T1, T2 >& p) {

  os << "{" <<p.first << ", " << p.second << "}";

  return os;

}

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }



const int INF = (ll)1e9;

const ll INFLL = (ll)1e18+1;

const ll MOD = (ll)1e9+7;

const double PI = acos(-1.0);

/*

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};

const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

const string dir = "DRUL";

*/



int main() {

    cin.tie(0);

    ios::sync_with_stdio(false);

    cout << fixed << setprecision(20);



    ll K;

    cin >> K;

    

    auto check = [&](ll X){

        // Xを桁ごとのvectorに変換

        vector<int> vx;

        ll tmp = X;

        while(tmp > 0){

            vx.push_back(tmp%10);

            tmp/=10;

        }

        reverse(all(vx));

        //桁数

        int N = vx.size();

        // dp[i][smaller][0以外を一度でも取ったか][最後の数字]

        ll dp[N+1][2][2][10];

        rep(i,N+1)rep(j,2)rep(k,2)rep(l,10)

            dp[i][j][k][l] = 0;



        dp[0][0][0][0] = 1;

        //dpの遷移

        for(int i = 0; i < N; i++)rep(j,2)rep(k,2)rep(l,10){

            for(int nxt = max(0, l-1); nxt <= (k ? min(l+1, (j ? 9:vx[i])): j ? 9 : vx[i]); nxt++){

                dp[i+1][j || nxt < vx[i]][k || nxt > 0][nxt] +=  dp[i][j][k][l];

            }

        }

        ll cnt = 0;

        rep(j,2)rep(l,10)cnt += dp[N][j][1][l];

        return cnt >= K;

    };

    ll ng = 0;

    ll ok = 1e18;

    while(ok - ng > 1){

        ll mid = (ok + ng) / 2;

        if(check(mid))ok = mid;

        else ng = mid;

    }

    cout << ok << endl;

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;

#define rep(i,N) for(int i=0;i<int(N);++i)

#define all(a) (a).begin(),(a).end()

typedef long long ll;



int main() {



    ll K;

    cin >> K;

    // Xを桁ごとのvectorに変換

    auto ll2vec = [&](ll X){

        vector<int> res;

        ll tmp = X;

        while(tmp > 0){

            res.push_back(tmp%10);

            tmp/=10;

        }

        reverse(all(res));

        return res;

    };

    auto check = [&](ll X){

        vector<int> vx = ll2vec(X);

        //桁数

        int N = vx.size();

        // dp[i][smaller][0以外を一度でも取ったか][最後の数字]

        ll dp[N+1][2][2][10];

        rep(i,N+1)rep(j,2)rep(k,2)rep(l,10)

            dp[i][j][k][l] = 0;

        dp[0][0][0][0] = 1;

        //dpの遷移

        for(int i = 0; i < N; i++)rep(j,2)rep(k,2)rep(l,10){

            for(int nxt = max(0, l-1); nxt <= (k ? min(l+1, (j ? 9:vx[i])): j ? 9 : vx[i]); nxt++){

                dp[i+1][j || nxt < vx[i]][k || nxt > 0][nxt] +=  dp[i][j][k][l];

            }

        }

        ll cnt = 0;

        rep(j,2)rep(l,10)cnt += dp[N][j][1][l];

        return cnt >= K;

    };



    ll ng = 0;

    ll ok = 3234566667;

    while(ok - ng > 1){

        ll mid = (ok + ng) / 2;

        if(check(mid))ok = mid;

        else ng = mid;

    }

    cout << ok << endl;

}

// Fastest known solution for this problem: