let solve k =
  let q = Queue.create () in
  let rec f i =
    if i < 10 then (
      Queue.push i q;
      f (i + 1)
    )
  in
  f 1;
  let rec f i =
    if i <= k then (
      let x = Queue.pop q in
      let m = x mod 10
      and j = ref i in
      let g y =
        if !j = k then print_int y
        else Queue.push y q;
        j := !j + 1
      in
      if m <> 0 then g (10 * x + m - 1);
      g (10 * x + m);
      if m <> 9 then g (10 * x + m + 1);
      f !j
    )
  in
  f 10

let ans k =
  if k < 10 then print_int k
  else solve k

let () = ans (read_int ())
