import scala.io.StdIn

object Main {

  def main(args: Array[String]) {
    val n = StdIn.readInt()
    for (i <- 1 to n) {
      if (toShow(i)) {
        print(s" $i")
      }
    }
    println()
  }
  
  def toShow(x: Int): Boolean = {
    var res = false
    if (x % 3 == 0) {
      res = true
    } else {
      var v = x
      while (v > 0 && !res) {
        if (v % 10 == 3) {
          res = true
        }
        v = v / 10
      }
    }
    res
  }
}

