"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const K = parseInt(arg[0].split(" ")[0]);
    
    let lunluns = [];
    
    let now = 1;
    let cnt = 0;
    
    while(lunluns.length < K) {
        if(String(now).length === 1) {
            lunluns.push(now);
            now++;
            continue;
        }
        
        lunluns.push(now);
        
        // 次のlunlun数
        for(let i=0; i<String(now).length; i++) {
            
            // 1の位に1足して成り立つならそれ
            let digit1 = String(now).split("")[String(now).length - (parseInt(i) + 1)];
            let digit2 = String(now).split("")[String(now).length - (parseInt(i) + 2)];
            
            // console.log("digit1:" + digit1);
            // console.log("digit2:" + digit2);
            
            // trueなら成り立つ
            if(Math.abs(digit2 - digit1) <= 1) {
                if(i === 0) {
                    
                    if(digit2 - digit1 === -1) {
                        now += 10 * (i + 1);
                        now -= i + 1;
                        // console.log("now:" + now)
                        break;
                    }
                    
                    // console.log("次のるんるんは1たすだけ")
                    now++;
                    break;
                } else {
                    
                    // console.log("次のるんるんは桁の計算")
                    now += 10 * i;
                    break;
                }
            }
        }
        
        cnt++;
        
        if(cnt > 100) break;
    }
    
    // console.log(lunluns);
    console.log(lunluns[K - 1]);
    
    
    /*
    1,2,3,4,5,6,7,8,9   1桁：9
    
    10,11,12,21,22,23,32,33,34,43,44,45,54,55,56... 2桁：27
    
    100,101,110,111,112,121,122,123 
    210,211,212,221,222,223,232,233,234
    321,322,323,332,333,334,343,344,345
    432,433,434,443,444,445,454,455,456
    
    3桁：71
    
    */
    
    // 1の位を優先的に上げてく
    // 不可能なら10の位を
    // それも不可能なら100の位を...
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));