fun main(args: Array<String>) {
	val n = readLine()!!.toInt()
	val ans = mutableListOf<Int>()

	for (i in 1 .. n) {
		var x = i
		while (x != 0) {
			if (x % 10 == 3 || i % 3 == 0) {
				ans.add(i)
				break
			}
			x /= 10
		}
	}
	println(" " + ans.joinToString(" "))
}

