import scala.io.StdIn.readInt
import scala.annotation.tailrec

object Main {
  @tailrec
  def find(x:Int,y:Int):String = {
    if(x>0) {
      if(x%10 == 3)  {
        " "+y
      } else {
        find(x/10,y)
      }
    } else {
      ""
    }
  }

  @tailrec
  def call(str:String, i:Int, n:Int):Unit = {
    if(i<=n) {
      if(i%3 == 0) {
        call(str + " "+i,i+1,n)
      } else {
        call(str + find(i,i),i+1,n)
      }
    } else {
      println(str)
    }
}

  def main(args: Array[String]) = {
    var n = readInt
    call("",1,n)
  }

}