object Main {
  def main(args: Array[String]): Unit = {
    val n = io.StdIn.readLine().toInt
    var i = 1
    var x = i
    do {
      x = i
      if(x % 3 == 0) {
        print(" " + i)
      } else {
        do {
          if(x % 10 == 3) {
            print(" " + i)
            x = 0
          }
          x = x / 10
        } while(x != 0)
      }
      i = i + 1
    } while(i <= n)
    println()
  }
}
