#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <numeric>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
#include <cassert>
#include <random>
#include <time.h>
#include <unordered_set>

using namespace std;
using Int = long long;

constexpr double EPS = 1e-10;
constexpr long long MOD = 1000000007;

long long mod_pow(long long x, long long n) {
    long long res = 1;
    for (int i = 0;i < 60; i++) {
        if (n >> i & 1) res = res * x % MOD;
        x = x * x % MOD;
    }
    return res;
}

long long my_mod_pow(long long x, long long n) {
	long long ret = 1;
	for (; n > 0; n >>= 1, x = x * x % MOD) {
		if (n & 1) {
			ret = ret * x % MOD;
		}
	}
	return ret;
}

template<typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

void fastInput() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

Int dp[15][2][15]; // dp[左からi桁][K以下が確定][i桁目の数]

Int calc_dp(Int K) {
    // K以下のルンルン数の個数を求めよ
    memset(dp, 0, sizeof(dp));
    vector<int> K_dig(15);
    Int tmp = K;
    for (int i = 0; i < 15; i++) {
        K_dig[14 - i] = tmp % 10;
        tmp /= 10;
    }

    int start;
    for (int i = 0; i < 15; i++) {
        if (K_dig[i] > 0) {
            start = i;
            for (int j = 0; j < K_dig[i]; j++) {
                dp[i][1][j] = 1;
            }
            dp[i][0][K_dig[i]] = 1;
            break;
        }
    }


    for (int i = start+1; i < 15; i++) {
        for (int j = 0; j < 10; j++) {
            if (j < K_dig[i]) {
                dp[i][1][j] += dp[i-1][0][j];
                if (j-1 >= 0) dp[i][1][j] += dp[i-1][0][j-1]; 
                if (j+1 <= 9) dp[i][1][j] += dp[i-1][0][j+1];

                dp[i][1][j] += dp[i-1][1][j];
                if (j-1 >= 0) dp[i][1][j] += dp[i-1][1][j-1];
                if (j+1 <= 9) dp[i][1][j] += dp[i-1][1][j+1];

                if (j >= 2) {
                    dp[i][1][j] += 1;
                }
            }

            if (j == K_dig[i]) {
                dp[i][0][j] += dp[i-1][0][j];
                if (j-1 >= 0) dp[i][0][j] += dp[i-1][0][j-1]; 
                if (j+1 <= 9) dp[i][0][j] += dp[i-1][0][j+1];

                dp[i][1][j] += dp[i-1][1][j];
                if (j-1 >= 0) dp[i][1][j] += dp[i-1][1][j-1];
                if (j+1 <= 9) dp[i][1][j] += dp[i-1][1][j+1];

                if (j >= 2) {
                    dp[i][1][j] += 1;
                }
            }

            if (j > K_dig[i]) {
                dp[i][1][j] += dp[i-1][1][j];
                if (j-1 >= 0) dp[i][1][j] += dp[i-1][1][j-1];
                if (j+1 <= 9) dp[i][1][j] += dp[i-1][1][j+1];

                if (j >= 2) {
                    dp[i][1][j] += 1;
                }
            }
        }
    }

    Int ret = 0;
    for (int i = 0; i < 10; i++) {
        ret += dp[14][0][i];
        ret += dp[14][1][i];
    }
    return ret - 1;
}

int main(void) {
    Int K; cin >> K;

    Int left = 0;
    Int right = 3234566667;
    while (right - left > 1) {
        Int mid = (left + right)/2;
        if (calc_dp(mid) >= K) {
            right = mid;
        } else {
            left = mid;
        }
    }

    cout << right << endl;
}


Measured memory_bytes: 888