#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
int main() {
  long long int N,K;
  cin >> K;
  long long int max=3234566667;
  int num=0;
  vector<int> A;
  for(long long int i=0;i<=max;i++){
    if(1<=i&&i<=12){
      A.push_back(i);
      num++;
    }
    else if(13<=i&&i<=99){
      if(abs(i%10-i/10)<=1){
       A.push_back(i);
        num++;
      }
    }
    else if(100<=i&&i<=999){
      if((abs(i%10-i/10%10)<=1)&&(abs(i/100-i/10%10)<=1)){
        A.push_back(i);
        num++;
      }
    }
    else if(1000<=i&&i<=9999){
      if((abs(i%10-i/10%10)<=1)&&(abs(i/100%10-i/10%10)<=1)&&(abs(i/1000%10-i/100%10)<=1)){
       A.push_back(i);
        num++;
      }
    }
    else if(10000<=i&&i<=99999){
      if((abs(i%10-i/10%10)<=1)&&(abs(i/100%10-i/10%10)<=1)&&(abs(i/1000%10-i/100%10)<=1)
         &&(abs(i/10000%10-i/1000%10)<=1)){
        A.push_back(i);
        num++;
      }
    }
    else if(100000<=i&&i<=999999){
      if((abs(i%10-i/10%10)<=1)&&(abs(i/100%10-i/10%10)<=1)&&(abs(i/1000%10-i/100%10)<=1)
         &&(abs(i/10000%10-i/1000%10)<=1)&&(abs(i/100000%10-i/10000%10)<=1)){
        A.push_back(i);
        num++;
      }
    }
    else if(1000000<=i&&i<=9999999){
      if((abs(i%10-i/10%10)<=1)&&(abs(i/100%10-i/10%10)<=1)&&(abs(i/1000%10-i/100%10)<=1)
         &&(abs(i/10000%10-i/1000%10)<=1)&&(abs(i/100000%10-i/10000%10)<=1)
         &&(abs(i/1000000%10-i/100000%10)<=1)){
        A.push_back(i);
        num++;
      }
    }
    else if(10000000<=i&&i<=99999999){
      if((abs(i%10-i/10%10)<=1)&&(abs(i/100%10-i/10%10)<=1)&&(abs(i/1000%10-i/100%10)<=1)
         &&(abs(i/10000%10-i/1000%10)<=1)&&(abs(i/100000%10-i/10000%10)<=1)
         &&(abs(i/1000000%10-i/100000%10)<=1)&&(abs(i/10000000%10-i/1000000%10)<=1)){
       A.push_back(i);
        num++;
      }
    }
    else if(100000000<=i&&i<=999999999){
      
      if((abs(i%10-i/10%10)<=1)&&(abs(i/100%10-i/10%10)<=1)&&(abs(i/1000%10-i/100%10)<=1)
         &&(abs(i/10000%10-i/1000%10)<=1)&&(abs(i/100000%10-i/10000%10)<=1)
         &&(abs(i/1000000%10-i/100000%10)<=1)&&(abs(i/10000000%10-i/1000000%10)<=1)
         &&(abs(i/100000000%10-i/10000000%10)<=1)){
        A.push_back(i);
        num++;
      }
    }
    else if(1000000000<=i&&i<=9999999999){
      
      if((abs(i%10-i/10%10)<=1)&&(abs(i/100%10-i/10%10)<=1)&&(abs(i/1000%10-i/100%10)<=1)
         &&(abs(i/10000%10-i/1000%10)<=1)&&(abs(i/100000%10-i/10000%10)<=1)
         &&(abs(i/1000000%10-i/100000%10)<=1)&&(abs(i/10000000%10-i/1000000%10)<=1)
         &&(abs(i/100000000%10-i/10000000%10)<=1)&&(abs(i/1000000000%10-i/100000000%10)<=1)){
        A.push_back(i);
        num++;
      }
    }
    if(i==130000000||i==240000000||i==350000000||i==460000000||i==570000000
       ||i==680000000||i==790000000){
      i+=79999999;
    }
    if(i==13000000||i==24000000||i==35000000||i==46000000||i==57000000
       ||i==68000000||i==79000000){
      i+=7999999;
    }
    if(i==1300000||i==2400000||i==3500000||i==4600000||i==5700000
       ||i==6800000||i==7900000){
      i+=799999;
    }
    if(i==130000||i==240000||i==350000||i==460000||i==570000
       ||i==680000||i==790000){
      i+=79999;
    }
    if(i==910000000){
      i+=69999999;
    }
    if(i==91000000){
      i+=6999999;
    }
    if(i==9100000){
      i+=699999;
    }
    if((i%10000000==1234568)||(i%10000000==2345679)||(i%10000000==3456790)
       ||(i%10000000==4567900)||(i%10000000==5679000)||(i%10000000==6790000)
       ||(i%10000000==7900000)||(i%10000000==9000000)){
      i+=864000;
    }
    if((i%1000000==123457)||(i%1000000==234568)||(i%1000000==345679)
       ||(i%1000000==456790)||(i%1000000==567900)||(i%1000000==679000)
       ||(i%1000000==790000)||(i%1000000==900000)){
      i+=86400;
    }
    if((i%100000==12346)||(i%100000==23457)||(i%100000==34568)||(i%100000==45679)
       ||(i%100000==56790)||(i%100000==67900)||(i%100000==79000)||(i%100000==90000)){
      i+=8600;
    }
    if((i%10000==1235)||(i%10000==2346)||(i%10000==3457)||(i%10000==4568)
       ||(i%10000==5679)||(i%10000==6790)||(i%10000==7900)||(i%10000==9000)){
      i+=860;
    }
    if((i%1000==124)||(i%1000==235)||(i%1000==346)||(i%1000==457)
       ||(i%1000==568)||(i%1000==679)||(i%1000==790)||(i%1000==901)){
      i+=85;
    }
    if((i/10%10==1&&i%10==3)||(i/10%10==2&&i%10==4)
      ||(i/10%10==3&&i%10==5)||(i/10%10==4&&i%10==6)||(i/10%10==5&&i%10==7)
      ||(i/10%10==6&&i%10==8)||(i/10%10==7&&i%10==9)||(i/10%10==9&&i%10==0)){
      i+=7;
    }
    if(num==K){
      N=i;
      break;
    }
  }
  
  cout << N;
  cout << endl;
  return 0;
}


Measured memory_bytes: 892