object Main {

    def main(args: Array[String]) = {
        val sc = new java.util.Scanner(System.in)
        val n = sc.nextInt

        for( i <- 3 to n ) {
            if( i%3 == 0 || i.toString.contains("3") ) print(" " + i )
        }
        print("\n")
    }

}
