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

int main() {  
vector<int64_t> vec1;
  vector<int64_t> vec2;
  vector<int64_t> vec3;
 vector<int64_t> vec4;
 vector<int64_t> vec5;
 vector<int64_t> vec6;
 vector<int64_t> vec7;
 vector<int64_t> vec8;
 vector<int64_t> vec9;
  vector<int64_t> vec10;
 for(int64_t i=1;i<=9;i++){vec1.push_back(i);}
  for(int64_t i=0;i<vec1.size();i++){
 int64_t  k=vec1.at(i);
  int64_t l=k%10;
 if(l==0){vec2.push_back(10*k);
         vec2.push_back(10*k+1);}
    if(l==9){ vec2.push_back(10*k+9);
             vec2.push_back(10*k+8);}
   if(l<=8&&l>=1){ vec2.push_back(10*k+l);
                  vec2.push_back(10*k+l-1);
                  vec2.push_back(10*k+l+1);}}
  
  for(int64_t i=0;i<vec2.size();i++){
 int64_t  k=vec2.at(i);
  int64_t l=k%10;
 if(l==0){vec3.push_back(10*k);
         vec3.push_back(10*k+1);}
    if(l==9){ vec3.push_back(10*k+9);
             vec3.push_back(10*k+8);}
   if(l<=8&&l>=1){ vec3.push_back(10*k+l);
                  vec3.push_back(10*k+l-1);
                  vec3.push_back(10*k+l+1);}}

  for(int64_t i=0;i<vec3.size();i++){
 int64_t  k=vec3.at(i);
  int64_t l=k%10;
 if(l==0){vec4.push_back(10*k);
         vec4.push_back(10*k+1);}
    if(l==9){ vec4.push_back(10*k+9);
             vec4.push_back(10*k+8);}
   if(l<=8&&l>=1){ vec4.push_back(10*k+l);
                  vec4.push_back(10*k+l-1);
                  vec4.push_back(10*k+l+1);}}

for(int64_t i=0;i<vec4.size();i++){
       int64_t  k=vec4.at(i);
            int64_t l=k%10;
         if(l==0){vec5.push_back(10*k);
                  vec5.push_back(10*k+1);}
        if(l==9){ vec5.push_back(10*k+9);
                  vec5.push_back(10*k+8);}
  if(l<=8&&l>=1){ vec5.push_back(10*k+l);
                  vec5.push_back(10*k+l-1);
                  vec5.push_back(10*k+l+1);}}

for(int64_t i=0;i<vec5.size();i++){
       int64_t  k=vec5.at(i);
            int64_t l=k%10;
         if(l==0){vec6.push_back(10*k);
                  vec6.push_back(10*k+1);}
        if(l==9){ vec6.push_back(10*k+9);
                  vec6.push_back(10*k+8);}
  if(l<=8&&l>=1){ vec6.push_back(10*k+l);
                  vec6.push_back(10*k+l-1);
                  vec6.push_back(10*k+l+1);}}

for(int64_t i=0;i<vec6.size();i++){
       int64_t  k=vec6.at(i);
            int64_t l=k%10;
         if(l==0){vec7.push_back(10*k);
                  vec7.push_back(10*k+1);}
        if(l==9){ vec7.push_back(10*k+9);
                  vec7.push_back(10*k+8);}
  if(l<=8&&l>=1){ vec7.push_back(10*k+l);
                  vec7.push_back(10*k+l-1);
                  vec7.push_back(10*k+l+1);}}
  
for(int64_t i=0;i<vec7.size();i++){
       int64_t  k=vec7.at(i);
            int64_t l=k%10;
         if(l==0){vec8.push_back(10*k);
                  vec8.push_back(10*k+1);}
        if(l==9){ vec8.push_back(10*k+9);
                  vec8.push_back(10*k+8);}
  if(l<=8&&l>=1){ vec8.push_back(10*k+l);
                  vec8.push_back(10*k+l-1);
                  vec8.push_back(10*k+l+1);}}
  
for(int64_t i=0;i<vec8.size();i++){
       int64_t  k=vec8.at(i);
            int64_t l=k%10;
         if(l==0){vec9.push_back(10*k);
                  vec9.push_back(10*k+1);}
        if(l==9){ vec9.push_back(10*k+9);
                  vec9.push_back(10*k+8);}
  if(l<=8&&l>=1){ vec9.push_back(10*k+l);
                  vec9.push_back(10*k+l-1);
                  vec9.push_back(10*k+l+1);}}
  

for(int64_t i=0;i<vec9.size();i++){
       int64_t  k=vec9.at(i);
            int64_t l=k%10;
         if(l==0){vec10.push_back(10*k);
                  vec10.push_back(10*k+1);}
        if(l==9){ vec10.push_back(10*k+9);
                  vec10.push_back(10*k+8);}
  if(l<=8&&l>=1){ vec10.push_back(10*k+l);
                  vec10.push_back(10*k+l-1);
                  vec10.push_back(10*k+l+1);}}
  

  
  
  int64_t b;
   int64_t a=0;
  cin>>b;
       int64_t m;
  vector<int64_t> vec{9, 26, 75 ,217 ,629 ,1826, 5307, 15438 ,44941 ,130900};
    while(b>0){
    m=b;
    b=b-vec.at(a);
    a++;}
  if(a==1){sort(vec1.begin(), vec1.end()); 
           cout<<vec1.at(m-1)<<endl;}
   if(a==2){sort(vec2.begin(), vec2.end()); 
            cout<<vec2.at(m-1)<<endl;}
   if(a==3){sort(vec3.begin(), vec3.end()); 
           cout<<vec3.at(m-1)<<endl;}
   if(a==4){sort(vec4.begin(), vec4.end());
            cout<<vec4.at(m-1)<<endl;}
   if(a==5){sort(vec5.begin(), vec5.end()); 
           cout<<vec5.at(m-1)<<endl;}
   if(a==6){sort(vec6.begin(), vec6.end()); 
           cout<<vec6.at(m-1)<<endl;}
   if(a==7){sort(vec7.begin(), vec7.end()); 
            cout<<vec7.at(m-1)<<endl;}
   if(a==8){sort(vec8.begin(), vec8.end()); 
           cout<<vec8.at(m-1)<<endl;}
   if(a==9){sort(vec9.begin(), vec9.end());
            cout<<vec9.at(m-1)<<endl;}
   if(a==10){sort(vec10.begin(), vec10.end()); 
             
             cout<<vec10.at(m-1)<<endl;}
  
  
}


Measured memory_bytes: 1976