/**
  * 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).foldLeft("") {
      (str, i) => {
        str + (
          if (i % 3 == 0 || i.toString.contains("3"))
            s" $i"
          else
            ""
          )
      }
    }
    println(result)
  }
}