import scala.io.StdIn.readInt

object Main extends App {
  val n  = readInt()
  val xs = for {
    i <- 3 to n
    if i % 3 == 0 || i.toString.contains('3')
  } yield i

  println(s" ${xs.mkString(" ")}")
}

