#include <bits/stdc++.h>
using namespace std;

int main() {
  int K;
  cin >> K;
  queue<long long> q;
  for (int i = 1; i <= 9; ++i)
    q.push(i);
  for (int i = 0; i < K - 1; ++i) {
    long long X = q.front();
    q.pop();
    if (X % 10 != 0)
      q.push(X * 10 + X % 10 - 1);
    q.push(X * 10 + X % 10);
    if (X % 10 != 9)
      q.push(X * 10 + X % 10 + 1);
  }
  cout << q.front() << endl;
}