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 =
    let x = Queue.pop q in
    if i = k then x
    else (
      let m = x mod 10 in
      if m <> 0 then Queue.push (10 * x + m - 1) q;
      Queue.push (10 * x + m) q;
      if m <> 9 then Queue.push (10 * x + m + 1) q;
      f (i + 1)
    )
  in
  f 1

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

let () =
  print_int (ans (read_int ()))
