std::queue<LL> q;
int k;

int main() {
    for (int i = 1; i <= 9; ++i)    q.push(i);
    read(k);
    for (int i = 1; i < k; ++i) {
        LL a = q.front();
        int dig = a % 10;
        q.pop();
        if (dig != 0)   q.push(a * 10 + dig - 1);
        q.push(a * 10 + dig);
        if (dig != 9)   q.push(a * 10 + dig + 1);
    }
    printf("%lld\n", q.front());
    return 0;
}