// Lunlun Number

func main() {
    let k = Int(readLine()!)!
    var rest = k - 9

    var lunlun: [[Int]] = []

    var digits = 0
    lunlun.append([1,2,3,4,5,6,7,8,9])
    var count = 9

    while count < k {
        var currentLunlun: [Int] = []
        for i in lunlun[digits] {
            let lastNumber = i % 10
            switch lastNumber {
            case 0:
                currentLunlun.append(i * 10 + lastNumber)
                currentLunlun.append(i * 10 + lastNumber + 1)
            case 9:
                currentLunlun.append(i * 10 + lastNumber - 1)
                currentLunlun.append(i * 10 + lastNumber)
            default:
                currentLunlun.append(i * 10 + lastNumber - 1)
                currentLunlun.append(i * 10 + lastNumber)
                currentLunlun.append(i * 10 + lastNumber + 1)
            }
        }

        if rest <= currentLunlun.count {
            print(currentLunlun[rest-1])
            return
        }
        rest -= currentLunlun.count
        lunlun.append(currentLunlun)
        count += currentLunlun.count
        digits += 1
    }
    print(lunlun[0][k-1])
}

main()