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{
      do {
        if(x % 10 == 3) {
          buff += x
        }
        x = x / 10
      } while(x != 0)
    } 
  }
  println(" " + buff.mkString(" "))
}
