#include <bits/stdc++.h>
using namespace std;
void dfs(long long n, vector<long long> &lunlun) {
  if (n > 3234566667) return;
  lunlun.push_back(n);
  if (n % 10 < 9) dfs(n * 10 + (n % 10) + 1, lunlun);
  dfs(n * 10 + (n % 10), lunlun);
  if (n % 10 > 0) dfs(n * 10 + (n % 10) - 1, lunlun);
}
signed main() {
  long long k;
  cin >> k;
  vector<long long> lunlun;
  for (long long i = 1; i <= 9; i++) {
    dfs(i, lunlun);
  }
  sort(lunlun.begin(), lunlun.end());
  cout << lunlun[k - 1] << endl;
}
