#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
typedef unsigned int uint;
typedef unsigned long long ull;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
template <class T> using VVV = V<VV<T>>;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;
void yesno(bool ok, string yes = "Yes", string no = "No") {
    if (ok) {
        cout << yes << endl;
    } else {
        cout << no << endl;
    }
}

ll dp[20][20];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll K;
    cin >> K;
    REP(i, 0, 10) {
        dp[9][i] = 1;
    }
    PER(i, 9, 0) {
        REP(j, 0, 10) {
            if (j < 9) {
                dp[i - 1][j + 1] += dp[i][j];
            }
            dp[i - 1][j] += dp[i][j];
            if (j > 0) {
                dp[i - 1][j - 1] += dp[i][j];
            }
        }
    }
    ll rowsum[10];
    fill(rowsum, rowsum + 10, 0);
    REP(i, 0, 10) {
        REP(j, 1, 10) {
            rowsum[i] += dp[9 - i][j];
        }
    }
    REP(i, 1, 10) {
        rowsum[i] += rowsum[i - 1];
    }
    ll firstketa = 0;
    REP(i, 0, 10) {
        if (rowsum[i] > K) {
            firstketa = 9 - i;
            break;
        }
    }
    ll now = 0;
    ll sum = 0;
    if (firstketa < 9) {
        sum = rowsum[9 - firstketa - 1];
    }
    ll ans = 0;
    K--;
    REP(i, 1, 10) {
        // cout << sum << endl;
        if (sum + dp[firstketa][i] > K) {
            now = i;
            ans += i;
            REP(j, 0, 9 - firstketa) {
                ans *= 10;
            }
            break;
        }
        sum += dp[firstketa][i];
    }
    REP(i, firstketa + 1, 10) {
        ll p[3] = {now - 1, now, now + 1};
        REP(j, 0, 3) {
            ll num = p[j];
            if (num < 0 || num > 9) {
                continue;
            }
            if (sum + dp[i][num] > K) {
                now = num;
                ll plus = p[j];
                REP(k, 0, 9 - i) {
                    plus *= (ll)10;
                }
                ans += plus;
                break;
            }
            sum += dp[i][num];
        }
    }
    // REP(i, 0, 10) {
    //     REP(j, 0, 10) {
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << endl;
    // }
    // REP(i, 0, 10) {
    //     cout << rowsum[i] << " ";
    // }
    // cout << endl;
    cout << ans << endl;
}


Measured memory_bytes: 256