// 入力マクロ
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}


/// `n`を十進法で表したときの桁数
pub fn scale_dight(n: usize) -> usize {
    if n == 0 {
        return 1;
    }
    let mut count = 0;
    let mut n = n;
    while n >= 1 {
        n /= 10;
        count += 1;
    }
    count
}
pub fn dight_vec(
    n: usize,
) -> Vec<usize> {
    let mut idx = scale_dight(n) - 1;
    let mut ret = Vec::new();
    loop {
        ret.push(n / 10usize.pow(idx as u32) % 10);
        if idx == 0 {
            break;
        }
        idx -= 1;
    }
    ret
}

use std::collections::VecDeque;

fn main() {
    input! {
        n: usize
    }

    let mut stack = VecDeque::new();
    let mut lunlun = vec![];
    for i in 1u64..10u64 {
        stack.push_back(i);
        lunlun.push(i);
    }
    let mut count = 9usize;

    while count < n {
        let p = stack.pop_front().unwrap();
        match p % 10 {
            0 => {
                let a = p * 10;
                let b = p * 10 + 1;
                count += 2;
                stack.push_back(a);
                stack.push_back(b);
                lunlun.push(a);
                lunlun.push(b);
            }
            9 => {
                let a = p * 10 + 8;
                let b = p * 10 + 9;
                count += 2;
                stack.push_back(a);
                stack.push_back(b);
                lunlun.push(a);
                lunlun.push(b);
            }
            r => {
                let a = p * 10 + r - 1;
                let b = p * 10 + r;
                let c = p * 10 + r + 1;
                count += 3;
                stack.push_back(a);
                stack.push_back(b);
                stack.push_back(c);
                lunlun.push(a);
                lunlun.push(b);
                lunlun.push(c);
            }
        }
    }

    // println!("{:?}", lunlun);

    println!("{}", lunlun[n-1]);


    // // dp[桁数][上の桁がnと等しいか][上の桁までがルンルン]
    // let mut dp = vec![(0, 0); d];

    // if d == 1 {
    //     dp[0].0 = 1;
    //     dp[0].1 = n;
    // } else {
    //     dp[0].0 = 0;
    //     dp[0].1 = 9;
    // }

    // for i in 1..d {
    //     if dp[i-1].0 == 1 {}
    // }
}


Measured memory_bytes: 6396