import java.util.Scanner

fun main(args:Array<String>){
    val cin = Scanner(System.`in`)
    val n = cin.nextInt()

    loop@ for(i in 1..n){
	
	var x = i

	if(x % 3 == 0){
	    print(" $i")
	    continue@loop
	}
	
	while(x != 0){
	    if(x % 10 == 3 ){
	        print(" $i")
	        continue@loop
	    }
	x /= 10
	}
    }
    println()
}

