#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  int64_t k;
  cin >> k;
  if(k<=9){
    cout << k << endl;
    return 0;
  }
  int cnt=9;
  vector<int64_t> k1={1,2,3,4,5,6,7,8,9,0};
  vector<int64_t> k2;
  vector<int64_t> k3;
  vector<int64_t> k4;
  vector<int64_t> k5;
  vector<int64_t> k6;
  vector<int64_t> k7;
  vector<int64_t> k8;
  vector<int64_t> k9;
  vector<int64_t> k10;
  for(int64_t p: k1){
    int64_t w=p;
    k2.push_back(w*10+p);
    if(w>0)k2.push_back((w-1)*10+p);
    if(w!=9)k2.push_back((w+1)*10+p);
  }
  sort(k2.begin(),k2.end());
  for(int64_t p: k2){
    int64_t w=p/10;
    k3.push_back(w*100+p);
    if(w>0)k3.push_back((w-1)*100+p);
    if(w!=9)k3.push_back((w+1)*100+p);
  }
  sort(k3.begin(),k3.end());
  for(int64_t p: k3){
    int64_t w=p/100;
    k4.push_back(w*1000+p);
    if(w>0)k4.push_back((w-1)*1000+p);
    if(w!=9)k4.push_back((w+1)*1000+p);
  }
  sort(k4.begin(),k4.end());
  for(int64_t p: k4){
    int64_t w=p/1000;
    k5.push_back(w*10000+p);
    if(w>0)k5.push_back((w-1)*10000+p);
    if(w!=9)k5.push_back((w+1)*10000+p);
  }
  sort(k5.begin(),k5.end());
  for(int64_t p: k5){
    int64_t w=p/10000;
    k6.push_back(w*100000+p);
    if(w>0)k6.push_back((w-1)*100000+p);
    if(w!=9)k6.push_back((w+1)*100000+p);
  }
  sort(k6.begin(),k6.end());
  for(int64_t p: k6){
    int64_t w=p/100000;
    k7.push_back(w*1000000+p);
    if(w>0)k7.push_back((w-1)*1000000+p);
    if(w!=9)k7.push_back((w+1)*1000000+p);
  }
  sort(k7.begin(),k7.end());
  for(int64_t p: k7){
    int64_t w=p/1000000;
    k8.push_back(w*10000000+p);
    if(w>0)k8.push_back((w-1)*10000000+p);
    if(w!=9)k8.push_back((w+1)*10000000+p);
  }
  sort(k8.begin(),k8.end());
  for(int64_t p: k8){
    int64_t w=p/10000000;
    k9.push_back(w*100000000+p);
    if(w>0)k9.push_back((w-1)*100000000+p);
    if(w!=9)k9.push_back((w+1)*100000000+p);
  }
  sort(k9.begin(),k9.end());
  for(int64_t p: k9){
    int64_t w=p/100000000;
    k10.push_back(w*1000000000+p);
    if(w>0)k10.push_back((w-1)*1000000000+p);
    if(w!=9)k10.push_back((w+1)*1000000000+p);
  }
  sort(k10.begin(),k10.end());
  int q=9;
  for(int64_t z: k2){
    if(z/10==0)continue;
    q++;
    if(k==q){
      cout << z << endl;
      return 0;
    }
  }
  for(int64_t z: k3){
    if(z/100==0)continue;
    q++;
    if(k==q){
      cout << z << endl;
      return 0;
    }
  }
  for(int64_t z: k4){
    if(z/1000==0)continue;
    q++;
    if(k==q){
      cout << z << endl;
      return 0;
    }
  }
  for(int64_t z: k5){
    if(z/10000==0)continue;
    q++;
    if(k==q){
      cout << z << endl;
      return 0;
    }
  }
  for(int64_t z: k6){
    if(z/100000==0)continue;
    q++;
    if(k==q){
      cout << z << endl;
      return 0;
    }
  }
  for(int64_t z: k7){
    if(z/1000000==0)continue;
    q++;
    if(k==q){
      cout << z << endl;
      return 0;
    }
  }
  for(int64_t z: k8){
    if(z/10000000==0)continue;
    q++;
    if(k==q){
      cout << z << endl;
      return 0;
    }
  }
  for(int64_t z: k9){
    if(z/100000000==0)continue;
    q++;
    if(k==q){
      cout << z << endl;
      return 0;
    }
  }
  for(int64_t z: k10){
    if(z/1000000000==0)continue;
    q++;
    if(k==q){
      cout << z << endl;
      return 0;
    }
  }
}  


Measured memory_bytes: 2996