import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdlib;

void main() {
    auto K = readln.chomp.to!int;
    long[] ans = iota(1L, 10L).array;

    int idx = 0;

    while (idx < K) {
        auto L = ans.length.to!int;
        foreach (i; idx..L) {
            auto ld = ans[i] % 10;
            if (ld > 0) ans ~= ans[i] * 10 + ld - 1;
            ans ~= ans[i] * 10 + ld;
            if (ld < 9) ans ~= ans[i] * 10 + ld + 1;
        }
        idx = L;
    }

    ans[K-1].writeln;
}
