let range start stop =
  let rec loop n acc =
    if n >= start then
      loop (n-1) (n :: acc)
    else
      acc
  in
  loop stop []

let check num =
  let rec include3 = function
    | 0 -> None
    | x when x mod 10 = 3 -> Some num
    | x -> include3 (x / 10)
  in
  if num mod 3 = 0 then
    Some num
  else
    include3 num

let filter_option xs =
  let f a x = match x with Some x -> x :: a | None -> a in
  List.rev (List.fold_left f [] xs)

let make n = range 1 n |> List.map check |> filter_option

let format ns = ns |>
                List.map string_of_int |>
                List.map ((^) " ") |>
                String.concat ""

let () =
  let n = read_int () in
  print_endline (format (make n))