#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int K, A=0;
  long long X;
  cin >> K;
  vector<long long> Q;
  rep(i, 9) Q.push_back(i+1);
  while(Q.size()<=K){
    X=Q.at(A);
    if(X%10!=0) Q.push_back(10*X+X%10-1);
    Q.push_back(10*X+X%10);
    if(X%10!=9) Q.push_back(10*X+X%10+1);
    A++;
  }
  cout << Q.at(K-1) << endl;
}