// This is my template for fast solving
 
#include <iostream>
#include <fstream>
#include <sstream>
#include <algorithm>
#include <utility>
#include <unordered_map>
#include <map>
#include <unordered_set>
#include <set>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <memory>
#include <initializer_list>
#include <iomanip>
#include <stack>
#include <bitset>
#include <cstdio>
// #include <complex>
// #include <random>
 
using namespace std;
 
using ll = long long;
using ull = unsigned long long;
using ld = long double;

// const ll INF = 1e18;
// const ld INF = 1e20;
const ll MOD = 998244353;
// const ld EPS = 1e-10;
// const ld PI = acos(-1);

template<typename T1, typename T2>
ostream& operator<<(ostream& os, const pair<T1, T2>& p);
template<typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2>& p);
 template<typename T>
ostream& operator<<(ostream& os, const vector<T>& v);
template<typename T>
istream& operator>>(istream& is, vector<T>& v);
template<typename T>
ostream& operator<<(ostream& os, const set<T>& s);
template<typename T1, typename T2>
ostream& operator<<(ostream& os, const map<T1, T2>& m);

vector<int> calc_z(const string& s);
ll binpow(ll a, ll m, ll mod);

map<pair<int, int>, ll> cnt;

ll count(int d, int len) {
    if (cnt.count({d, len}) == 1) {
        return cnt[{d, len}];
    }
    if (len == 1) {
        cnt[{d, len}] = 1;
        return 1;
    }
    if (d > 0) {
        cnt[{d, len}] += count(d - 1, len - 1);
    }
    cnt[{d, len}] += count(d, len - 1);
    if (d < 9) {
        cnt[{d, len}] += count(d + 1, len - 1);
    }
    return cnt[{d, len}];
}

void solve() {
    int k;
    cin >> k;
    vector<int> len(12);
    for (int l = 1; l <= 11; ++l) {
        len[l] += len[l - 1];
        for (int d = 1; d <= 9; ++d) {
            len[l] += count(d, l);
        }
    }
    int l = 0;
    while (len[l] < k) {
        ++l;
    }
    string res = "";
    int prev;
    k -= len[l - 1];
    for (int i = 1; i <= 9; ++i) {
        ll x = count(i, l);
        if (x >= k) {
            res += char('0' + i);
            prev = i;
            break;
        }
        k -= x;
    }
    --l;
    while (l > 0) {
        for (int i = prev - 1; i <= prev + 1; ++i) {
            if (i < 0) {
                continue;
            }
            if (count(i, l) >= k) {
                res += char('0' + i);
                prev = i;
                break;
            }
            k -= count(i, l);
        }
        --l;
    }
    cout << res << "\n";
}   
 
int main() {
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    // int t;
    // cin >> t;
    // for (int i = 1; i <= t; ++i) {
    //     cout << "Case #" << i << ": "; // CodeJam style
    //     solve();
    // }
 
    // int q;
    // cin >> q;
    // while (q--) {
    //     solve();
    // }

    solve();
 
    return 0;
}

template<typename T1, typename T2>
ostream& operator<<(ostream& os, const pair<T1, T2>& p) {
    os << p.first << " " << p.second;
    return os;
}

template<typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2>& p) {
    is >> p.first >>  p.second;
    return is;
}
 
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    bool first = true;
    for (const auto& x : v) {
        if (!first) {
            os << " ";
        }
        first = false;
        os << x;
    }
    return os;
}

template<typename T>
istream& operator>>(istream& is, vector<T>& v) {
    for (auto& elem : v) {
        is >> elem;
    }
    return is;
}

template<typename T>
ostream& operator<<(ostream& os, const set<T>& s) {
    bool first = true;
    for (auto x : s) {
        if (!first) {
            os << " ";
        }
        first = false;
        os << x;
    }
    return os;
}

template<typename T1, typename T2>
ostream& operator<<(ostream& os, const map<T1, T2>& m) {
    bool first = true;
    for (auto x : m) {
        if (!first) {
            os << "\n";
        }
        first = false;
        os << x;
    }
    return os;
}

vector<int> calc_z(const string& s) {
    int n = s.length();
    vector<int> z(n, 0);
    int l = 0, r = 0;
    for (int i = 1; i < n; ++i) {
        if (i <= r) {
            z[i] = min(z[i - l], r - i);
        }
        int j = i + z[i];
        while (j < n && s[j] == s[z[i]]) {
            ++z[i];
            ++j;
        }
        if (j >= r) {
            r = j - 1;
            l = i;
        }
    }
    return z;
}

ll binpow(ll a, ll m, ll mod = MOD) {
    ll res = 1;
    while (m) {
        if (m % 2) {
            res = res * a % mod;
            --m;
        } else {
            a = a * a % mod;
            m /= 2;
        }
    }
    return res;
}


Measured memory_bytes: 256