import scala.io.StdIn

object Main{
  def main(args: Array[String]){
    val in = StdIn.readLine()

    for(i <- 1 to in.toInt){
      var x = i
      if(x % 3 == 0){
        print(" " + i)
      }
      else{
        do{
          if(x % 10 == 3){
            print(" " + i)
          }

          x = x / 10
        }while(x != 0)
      }
    }

    println()
  }
}