object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n = sc.nextInt()
  println(" " + (1 to n).filter(i => isMultipleOf3(i) || hasNumberOf3(i)).mkString(" "))

  def isMultipleOf3(i: Int): Boolean = i % 3 == 0
  def hasNumberOf3(i: Int): Boolean = i % 10 == 3 || i / 10 == 3
}