#include<bits/stdc++.h>
using namespace std;

// macros
#define int long long 
#define TIME clock() * 1.0 / CLOCKS_PER_SEC
#define all(c) c.begin(), c.end()
#define PB push_back
#define MP make_pair
#define bitcount __builtin_popcount
#define watch(x) cerr<< (#x) << " is " << (x) <<"\n";
#define sz(x) ((int)((x).size()))
#define UNIQUE(c) (c).resize(unique(all(c)) - (c).begin())
#define pii2ll(p) ((ll)(p).first<<32 | (p).second)

// type definitions
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< vi > vvi;
typedef pair<int, int> pii;
typedef long double ld;

// template functions
template < typename A, typename B >
ostream &operator << ( ostream& os, const pair< A, B > & p ) {
    return os << "(" << p.first << ", " << p.second << ")";
}
template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
    os << "[";
    typename vector< T > :: const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "]";
}
template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
    os << "{";
    typename set< T > :: const_iterator it;
    for ( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "}";
}
template < typename A, typename B >
ostream &operator << ( ostream & os, const map< A, B > &v ) {
    os << "[";
    typename map< A, B >::const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << it -> first << " -> " << it -> second ;
    }
    return os << "]";
}
template<typename T>
T gcd(T a, T b) { if(a==0 or b==0) return a+b; return gcd(b, a%b) ; }
template<typename T>
T lcm(T a, T b) { if(a==0 or b==0) return 0; return a/gcd(a, b)*b; }

// random number generation
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

// constants
const long double eps = LDBL_EPSILON;
const int inf = 1e15;
const int modn = 1e9+7;
const int maxn = 2e5+3;

int dp[20][12][2][2];

int f(int n)
{
    vi a;
    int tmp = n;
    while(tmp) {
        a.PB(tmp%10);
        tmp /= 10;
    }
    reverse(all(a));
    memset(dp, -1, sizeof(dp));
    function<int(int, int, bool, bool)> solve = [&](int i, int prev, bool tight, bool pre) {
        if(i==sz(a)) {
            return (int)(pre ? 0 : 1);
        }

        int &ans = dp[i][prev][tight][pre];
        if(ans!=-1) return ans;

        ans = 0;
        int limit = (tight ? a[i] : 9);
        for(int dig=0; dig<=limit; dig++) {
            if(pre or abs(dig-prev)<=1)
            ans += solve(i+1, dig, tight&(dig==a[i]), pre&(dig==0));
        }
        return ans;
        // if(pre) {
        //     if(i==0) {
        //         for(int dig = 0; dig <= a[i]; dig++) {
        //             ans += solve(i+1, dig, pre&(dig==a[i]));
        //         }
        //     }
        //     else {
        //         for(int dig=0; dig<=a[i]; dig++) {
        //             if(abs(dig-prev)<=1) {
        //                 ans += solve(i+1, dig, pre&(dig==a[i]));
        //             }
        //         }
        //     }
        // }
        // else {
        //     for(int dig=0; dig<10; dig++) {
        //         if(abs(dig-prev)<=1) {
        //             ans += solve(i+1, dig, 0);
        //         }
        //     }
        // }
        // return ans;
    };
    return solve(0, 10, 1, 1);
}

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // Your code here
    int k;
    cin>>k;
    int low = 1, high = 1e18;
    while(low < high) {
        int mid = (low + high)/2;
        int no = f(mid);
        // watch(mid);
        // watch(no);
        if(k <= no) {
            high = mid;
        }
        else {
            low = mid + 1;
        }
    }
    cout << low << "\n";
    // watch(f(23));
    return 0;
}



Measured memory_bytes: 256