import std.algorithm;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

bool check (int n) {
  int last = n % 10;
  n /= 10;
  while (n > 0) {
    int x = n % 10;
    if (abs (x - last) != 1) return false;
    n /= 10;
  }
  return true;
}

void main() {
  int k;
  readf (" %d", &k);
  auto q = iota (1U, 10U).array;
  int left = 0;
  while (q.length <= k) {
    uint i = q[left++];
    int j = (i % 10);
    for (int d = -1; d <= 1; ++d) {
      int o = j + d;
      if (o < 0 || o > 9) continue;
      q ~= i * 10 + o; 
    }
  }
  //debug stderr.writeln (q);
  writeln (q[k-1]);
}

