object Main extends App {
  val scanner = new java.util.Scanner(System.in)
  val n = scanner.nextInt()

  val outputs = (1 to n).filter { i =>
    i % 3 == 0 || (i.toString).contains('3')
  }

  println(" " + outputs.mkString(" "))
}