/**
  * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_5_D
  * Structured Program I - Structured Programming
  */
object Main {
  def main(args: Array[String]): Unit = {
    val n = io.StdIn.readInt()
    val result = " " + (1 to n).filter(i => i % 3 == 0 || i.toString.contains("3")).mkString(" ")
    println(result)
  }
}