let () =
  let n = read_int () in
  let rec doit i acc =
    if i > n then List.rev acc
    else if (i mod 3 = 0) then doit (i + 1) (i :: acc)
    else begin
      match
        try Some (String.index (string_of_int i) '3')
        with _ -> None
      with
      | None -> doit (i + 1) acc
      | Some _ -> doit (i + 1) (i :: acc)
    end
  in
  List.iteri (fun i x ->
    if i = 0 then Printf.printf "%d" x
    else Printf.printf " %d" x)
    (doit 3 []);
  print_newline ()