#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 1000000007
#define print(A,n) for(ll i=0;i<n;++i)cout<<A[i]<<' ';cout<<endl;
#define take(A,n) for(ll i=0;i<n;++i)cin>>A[i];
//    for(auto& it : m)
void fastio(){ios_base::sync_with_stdio(false);cin.tie(NULL);}
//  priority_queue<ll int> pq;
//  priority_queue <ll int, vector<ll int>, greater<ll int> > pq;
//  vector<ll int> v;
//  vector< pair<ll int,ll int> > v;
//  set<ll int>::iterator it=s.begin();
//  unordered_map<  pair<ll int,ll int>, ll int> mp;
 
 
 int lis( int arr[], int n )  
{  
    int lis[n]; 
   
    lis[0] = 1;    
  
    /* Compute optimized LIS values in bottom up manner */
    for (int i = 1; i < n; i++ )  
    { 
        lis[i] = 1; 
        for (int j = 0; j < i; j++ )   
            if ( arr[i] > arr[j] && lis[i] < lis[j] + 1)  
                lis[i] = lis[j] + 1;  
    } 
  
    // Return maximum value in lis[] 
    return *max_element(lis, lis+n); 
}  
void computeLPSArray(char* pat, int M, int* lps) 
{ 
    // length of the previous longest prefix suffix 
    int len = 0; 
  
    lps[0] = 0; // lps[0] is always 0 
  
    // the loop calculates lps[i] for i = 1 to M-1 
    int i = 1; 
    while (i < M) { 
        if (pat[i] == pat[len]) { 
            len++; 
            lps[i] = len; 
            i++; 
        } 
        else // (pat[i] != pat[len]) 
        { 
            // This is tricky. Consider the example. 
            // AAACAAAA and i = 7. The idea is similar 
            // to search step. 
            if (len != 0) { 
                len = lps[len - 1]; 
  
                // Also, note that we do not increment 
                // i here 
            } 
            else // if (len == 0) 
            { 
                lps[i] = 0; 
                i++; 
            } 
        } 
    } 
} 
string longestCommonPrefix(string ar[], int n) 
{ 
  
    // If size is 0, return empty string 
    if (n == 0) 
        return ""; 
  
    if (n == 1) 
        return ar[0]; 
  
    // Sort the given array 
    sort(ar, ar + n); 
  
    // Find the minimum length from  
    // first and last string 
    int en = min(ar[0].size(),  
                 ar[n - 1].size()); 
  
    // Now the common prefix in first and  
    // last string is the longest common prefix 
    string first = ar[0], last = ar[n - 1]; 
    int i = 0; 
    while (i < en && first[i] == last[i]) 
        i++; 
  
    string pre = first.substr(0, i); 
    return pre; 
} 
bool isvalid(ll int x, ll int y, ll int m, ll int n)
{
    if(x<0||y<0||x>=m||y>=n)return 0;
    else return 1;
}
bool iscor(ll int x, ll int y, ll int m, ll int n)
{
    if(x==0||y==0||x==m-1||y==n-1)return 1;
    else return 0;
}

    
int main()
{
  fastio();
 
ll int T;
//cin>>T;
T=1;
ll int anscount=1,i;
while(T--)
{
 ll int k;
 cin>>k;
 
 queue<string> q;
 ll int count=0;
 string temp ="0";//cout<<temp<<endl;

 for(i=1;i<=9;i++)
 {
     temp="0";
    temp[0]+=i;
     //cout<<temp<<endl;
     q.push(temp);
     count++;
     if(count==k){cout<<temp<<endl;return 0;}
 }
 
 while(!q.empty())
 {
     
     
          temp = q.front();string s1="0";ll int  c=temp[temp.size()-1]-'0',c1;
         if(c==0)
         {
             s1[0]+=c;
             q.push(temp+s1);count++;if(count==k){cout<<temp+s1<<endl;return 0;}
             
             c++;
             s1="0";s1[0]+=c;
             q.push(temp+s1);count++;if(count==k){cout<<temp+s1<<endl;return 0;}
         }
         else if(c==9)
         {
              c--;
            s1="0";s1[0]+=c;
             q.push(temp+s1);count++;if(count==k){cout<<temp+s1<<endl;return 0;}
             c++;
              s1="0";s1[0]+=c;
             q.push(temp+s1);count++;if(count==k){cout<<temp+s1<<endl;return 0;}
            
         }
         else
         {
             c--;
             s1="0";s1[0]+=c;
             q.push(temp+s1);count++;if(count==k){cout<<temp+s1<<endl;return 0;}
               c++;
             s1="0";s1[0]+=c;
             q.push(temp+s1);count++;if(count==k){cout<<temp+s1<<endl;return 0;}
           c++;
            s1="0";s1[0]+=c;
             q.push(temp+s1);count++;if(count==k){cout<<temp+s1<<endl;return 0;}
            
             
         }
         q.pop();
             
     
 }
 
 //cout<<n<<endl;
 
  
  
  
}
    return 0;
}

Measured memory_bytes: 4864