import scala.io.StdIn.readLine

object Main extends App {

  val n:Int = readLine().toInt

  for (i <- 1 to n) {
    if (i.toString.contains("3")) {
      print("%d ".format(i))
    }
  }
  println()
}