let () =
  let n = Scanf.scanf "%d\n" (fun x -> x) in
  let f x = x mod 3 = 0 || String.contains (string_of_int x) '3' in
  let rec range x y = if x > y then [] else x :: range (x+1) y in
  Printf.printf " ";
  List.filter f (range 1 n) |> List.map string_of_int |> String.concat " " |> print_endline
    