object Main extends App {
	override def main(args: Array[String]) = {
		val sc = new java.util.Scanner(System.in)
		
		val n = sc.nextInt
		
		val sb:StringBuilder = new StringBuilder("")
		val res = (1 to n).filter(check).map(_ +"").reduceLeft((z,n) => z + " " + n)

		print(res)
	}
	
	def check(x : Int):Boolean = {
		check_mod3(x) ||
		check_contains3(x)
	}
	
	def check_mod3(x :Int):Boolean = {
		x % 3 == 0
	}
	def check_contains3(x : Int):Boolean = {
		val mod = x % 10
		if(mod == 3){
			return true
		}
		if(x / 10 > 0){
			return check_contains3(x/10)
		}
		return false
	}
}