import java.util.*

tailrec fun isInclude3(n: Int): Boolean = when {
    (n == 0) -> false
    (n % 10 == 3) -> true
    else -> isInclude3(n / 10)
}

fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`)
    val n = scanner.nextInt()
    (1..n).forEach { i ->
        when {
            (i % 3) == 0 -> print(" " + i)
            isInclude3(i) -> print(" " + i)
        }
    }
    println()
}
