#include <bits/stdc++.h>
using namespace std;
vector<long long> lunlun;
void make(long long x){
  if(x > 3234566667LL) return;
  lunlun.emplace_back(x);
  if(x%10 <= 8) make(x*10+(x%10+1));
  if(x%10 >= 1) make(x*10+(x%10-1));
  make(x*10+x%10);
}
int main(){
  int k; cin >> k;
  for(int i = 1; i <= 9; ++i) make(i);
  sort(lunlun.begin(), lunlun.end());
  cout << lunlun[--k] << '\n';
  return 0; 
}
