
import scala.collection.mutable.ListBuffer
import scala.io.StdIn

object Main extends App {

  val n = StdIn.readLine().toInt
  val buff = ListBuffer.empty[Int]
  (1 to n).foreach { i =>
    var x = i
    if(x % 3 == 0) {
      buff += x
    } else {
      var continue = true
      do {
        if(x % 10 == 3) {
          buff += i
          continue = false
        } else {
          x = x / 10
        }
      } while(x != 0 && continue)
    } 
  }
  println(" " + buff.mkString(" "))
}
