object Main {
  def main(args: Array[String]): Unit = {
    val n = io.StdIn.readInt()
    val output =
      (for {
        i <- 1 to n
        if i % 3 == 0 || include3(i)
      } yield s" $i").mkString
    println(output)
  }

  def include3(x: Int): Boolean = {
    var included = false
    var i = x
    while (!included && i > 0) {
      included |= i % 10 == 3
      i /= 10
    }
    included
  }
}