#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define int long long
#define all(X) (X).begin(), (X).end()
#define reset(X) memset(X, 0, sizeof(X))
#define mp(a, b) make_pair(a, b)
#define pb push_back
#define endl '\n'
using namespace __gnu_pbds;
using namespace std;
const int mod=1e9+7;
// const int mod=998244353;
const int INF=4e18+10;
const int MOD=mod;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;


bool no(string s)
{
    return !(s=="0011" || s=="0101"|| s=="1110" || s=="1111");
}

int pow(int a, int b)
{
    int prod=1;
    int mult=a%mod;
    while(b!=0)
    {
        if(b%2)
        {
            prod*=mult;
            prod%=mod;
        }
        mult*=mult;
        mult%=mod;
        b/=2;
    }
    return prod;
}
int inverse(int q)
{
   return pow(q, mod-2);
}
const int MAXN=100;
int dpe[MAXN][11][2];

int dp(const string & s, int index,int last, bool is_small)
{
    if(last<0)
        return 0;
    if(last>9)
        return 0;
    if(index==s.size())

    {
        return 1;
    }
    if(dpe[index][last][is_small?1:0]!=-1)
    {
        return dpe[index][last][is_small?1:0];
    }

    int &ans=dpe[index][last][is_small?1:0];
    if(is_small)
    {
        if(last==0)
        {
            ans=dp(s, index+1, 1, true)+ dp(s, index+1, 0, true);
        }
        else
        if(last==9)
        {
            ans=dp(s, index+1, 9, true)+dp(s, index+1, 8, true);
        }
        else
        {
            ans=dp(s, index+1, last-1, true)+dp(s, index+1, last, true)+ dp(s, index+1, last+1, true);
        }

    }
    else
    {
        int digit=s[index]-'0';

        if(last==0)
        {
            ans=0;
            if(0<=digit)
            ans+=dp(s, index+1, 0, (0<digit)?true:false);

            if(1<=digit)
            ans+=dp(s, index+1, 1, (1<digit)?true:false);
        }
        else
        if(last==9)
        {
            ans=0;
            if(9<=digit)
            ans+=dp(s, index+1, 9, true);
            if(8<=digit)
            ans+=dp(s, index+1, 8, (8<digit)?true:false);
        }
        else
        {
            ans=0;
            if(last-1<=digit)
            {
                ans+=dp(s, index+1, last-1,(last-1<digit)? true:false);
            }
            if(last<=digit)
            ans+=dp(s, index+1, last,(last<digit)? true:false);
            if(last+1<=digit) 
            ans+= dp(s, index+1, last+1,(last+1<digit)? true:false);
        }
    }
    return ans;

}


signed main()

{
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);  
       cout.tie(NULL);
     #ifndef ONLINE_JUDGE
        if(fopen("INPUT.txt","r"))
        {
        freopen ("INPUT.txt" , "r" , stdin);
        freopen ("OUTPUT.txt" , "w" , stdout);
        }
     #endif
    auto clk=clock(); 
    // -------------------------------------Code starts here---------------------------------------------------------------------     
    int k;
    cin>>k;
    int lo=1, hi=1e18;


    while(lo<hi)
    {

        for(int i=0;i<MAXN;i++)
        {
            for(int j=0;j<10;j++)
            {
                for(int k=0;k<2;k++)
                    dpe[i][j][k]=-1;
            }
        }
        int mid=(lo+hi)/2;
        int cnt=0;
        string s=to_string(mid);
        for(int j=1;j<to_string(mid)[0]-'0';j++)
            cnt+=dp(s, 1,j, true);
        cnt+=dp(s, 1, to_string(mid)[0]-'0', false);
        int len=s.size();
        for(int j=2;j<=s.size();j++)
        {
            for(int k=1;k<=9;k++)
             cnt+=dp(s, j, k, true);
        }
        if(cnt>=k)
        {
            hi=mid;
        }
        else
            lo=mid+1;
    }
    cout<<lo<<endl;
    // -------------------------------------Code ends here------------------------------------------------------------------

 
 
    clk = clock() - clk;
    cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << "\n";
    return 0;
 }


Measured memory_bytes: 256