import scala.io.StdIn

/**
  * AOJ
  */
object Main {

  def main(args: Array[String]): Unit = {

    val n = StdIn.readInt()
    for(i <- 1 to n){
      if(check_num(i)){print(" %d".format(i))}
    }
    println()
  }

  def check_num(n:Int): Boolean = n match {
    case n if n % 3 == 0 => true
    case n if(n.toString.contains("3")) => true
    case _ => false
  }
}