#include <bits/stdc++.h>
#include <time.h>
#include <stdlib.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define ull unsigned long long
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/__gcd((a),(b))
#define clr(x) x.clear()
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vi>
#define mp make_pair
#define hell 1000000007
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define all(a) a.begin(),a.end()
#define ign cin.ignore();

#define o_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define o_setll tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
//member functions :
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set

using namespace std;
using namespace __gnu_pbds;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef MY_PROJECT
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

long long dp[20][2][10][2];

string number;

long long digit(int idx, int tight,int last,int started)
{
    if (idx == -1){
        if(started==1)
            return 1;
        else return 0;
    }

    if(last!=-1){
    if (dp[idx][tight][last][started] != -1)
        return dp[idx][tight][last][started];
    }

    long long ret = 0;

    int k = (tight)? number[idx]-'0' : 9;
    int mini,maxi;
    if(last==-1){
        mini=0;
        maxi=9;
    }
    else{
        mini=last-1;
        maxi=last+1;
    }
    for (int i = max(0,mini); i <= min(k,maxi) ; i++)
    {
        int newTight = ((number[idx]-'0') == i)? tight : 0;

        if(i>0){
            started=1;
        }
        if(started==0){
            ret += digit(idx-1, newTight, -1, started);
        }
        else
            ret += digit(idx-1, newTight, i, started);
    }
    if (last!=-1)
      dp[idx][tight][last][started] = ret;


    return ret;
}

int main()
{
    IOS
    ll k;
    cin>>k;
    ll high=1e18;
    ll low=1;
    ll mid;
    while(high-low>1){
        memset(dp,-1,sizeof(dp));
        mid=(high+low)/2;
        number=to_string(mid);
        reverse(all(number));
        ll res=digit((int)number.length()-1,1,-1,0);
        if(res>=k){
            high=mid;
        }
        else{
            low=mid+1;
        }
    }
    memset(dp,-1,sizeof(dp));
    number=to_string(low);
    reverse(all(number));
    ll res=digit((int)number.length()-1,1,-1,0);
    if(res>=k){
        cout<<low<<"\n";
    }
    else cout<<high<<"\n";
    return 0;
}


Measured memory_bytes: 256