import scala.io.StdIn.readInt

object Main {

  def find(y:Int):String = {
    var x = y
    while(x>0 && x%10!=3) {
        x = x/10
    }
    if(x%10 == 3) " "+y else ""
  }

  def call(i:Int, n:Int):Unit = {
    var str = ""
    for(i <- 1 to n) {
      if(i%3 == 0){
        str += " "+i
      } else {
        find(i)
      }
    }
    println(str)
}

  def main(args: Array[String]) = {
    var n = readInt
    call(1,n)
  }

}