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