import scala.util.control.Breaks
object Main extends App {
  val n = readLine().toInt

  for (i <- 1 to n) {
    var x = i

    if (x % 3 == 0) {
      print(" %d".format(i))
    } else {
      val b = new Breaks()
      b.breakable {
        do {
          if (x % 10 == 3) {
            print(" %d".format(i))
            b.break
          }
          x /= 10
        } while ( x != 0)
      }
    }
  }
  println()
}

