void main() {
  problem();
}

class LunlunNumber {
  immutable long number;

  this(long n) {
    deb([n]);
    number = n;

    if (!isValid) {
      throw new Exception("invalid number");
    }
  }

  bool isValid() {
    long n = number;
    while(n > 10) {
      const tail = n % 10;
      n /= 10;
      const preTail = n % 10;
      const spread = tail - preTail;
      if (-1 > spread || spread > 1) return false;
    }

    return true;
  }

  LunlunNumber next() {
    if (number < 10) return new LunlunNumber(number + 1);

    long n = number;
    long next = number;
    long dec = 1;
    bool isMiddle;
    while(n >= 10) {
      const tail = n%10;
      next -= dec*tail;
      n /= 10;

      const preTail = n%10;
      if (tail < 9 && preTail >= tail) {
        next += dec*(tail);
        isMiddle = true;
        break;
      }

      dec *= 10;
    }

    if (n < number) {
      next += dec;
    }

    if (isMiddle) dec *= 10;

    while(dec > 1) {
      const head = (next % (dec * 10)) / dec;
      const postHead = (next % dec) * 10 / dec;
      deb([dec, head, postHead]);
      dec /= 10;
      if (head - postHead > 1) {
        next -= dec * postHead;
        next += head == 0 ? 0 : dec * (head - 1);
      }
    }

    return new LunlunNumber(next);
  }

  override string toString() {
    return number.to!string;
  }

}

void problem() {
  const K = scan!long;

  long solve() {
    auto lunlun = new LunlunNumber(1);
    foreach(i; 1..K) {
      lunlun = lunlun.next();
    }

    return lunlun.number;
  }

  solve().writeln;
}

// ----------------------------------------------

import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.functional;
T[][] combinations(T)(T[] s, in int m) {   if (!m) return [[]];   if (s.empty) return [];   return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; }
T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }
void deb(T ...)(T t){ debug writeln(t); }
alias Point = Tuple!(long, "x", long, "y");

// -----------------------------------------------
