import java.util.*;
class Main{
    Scanner sc=new Scanner(System.in);
    void main(){
	int n=sc.nextInt();
	for(int i=1;i<=n;i++){
	    boolean e=false;
	    if(i%3==0)e=true;
	    for(int j=1;j<100000;j*=10)if(i/j%10==3)e=true;
	    if(e)System.out.print(" "+i);
	}
	System.out.println();
    }
    public static void main(String[]ag){
	new Main().main();
    }
} import java.util.*; util.* java class Main{
    Scanner sc=new Scanner(System.in);
    void main(){
	int n=sc.nextInt();
	for(int i=1;i<=n;i++){
	    boolean e=false;
	    if(i%3==0)e=true;
	    for(int j=1;j<100000;j*=10)if(i/j%10==3)e=true;
	    if(e)System.out.print(" "+i);
	}
	System.out.println();
    }
    public static void main(String[]ag){
	new Main().main();
    }
} Main Scanner sc=new Scanner(System.in); sc new Scanner(System.in) void main(){
	int n=sc.nextInt();
	for(int i=1;i<=n;i++){
	    boolean e=false;
	    if(i%3==0)e=true;
	    for(int j=1;j<100000;j*=10)if(i/j%10==3)e=true;
	    if(e)System.out.print(" "+i);
	}
	System.out.println();
    } main {
	int n=sc.nextInt();
	for(int i=1;i<=n;i++){
	    boolean e=false;
	    if(i%3==0)e=true;
	    for(int j=1;j<100000;j*=10)if(i/j%10==3)e=true;
	    if(e)System.out.print(" "+i);
	}
	System.out.println();
    } int n=sc.nextInt(); n sc.nextInt() sc.nextInt sc for(int i=1;i<=n;i++){
	    boolean e=false;
	    if(i%3==0)e=true;
	    for(int j=1;j<100000;j*=10)if(i/j%10==3)e=true;
	    if(e)System.out.print(" "+i);
	} int i=1; int i=1; i 1 i<=n i n i++ i++ i {
	    boolean e=false;
	    if(i%3==0)e=true;
	    for(int j=1;j<100000;j*=10)if(i/j%10==3)e=true;
	    if(e)System.out.print(" "+i);
	} {
	    boolean e=false;
	    if(i%3==0)e=true;
	    for(int j=1;j<100000;j*=10)if(i/j%10==3)e=true;
	    if(e)System.out.print(" "+i);
	} boolean e=false; e false if(i%3==0)e=true; i%3==0 i%3 i 3 0 e=true e true for(int j=1;j<100000;j*=10)if(i/j%10==3)e=true; int j=1; int j=1; j 1 j<100000 j 100000 j*=10 j*=10 j 10 if(i/j%10==3)e=true; if(i/j%10==3)e=true; i/j%10==3 i/j%10 i/j i j 10 3 e=true e true if(e)System.out.print(" "+i); e System.out.print(" "+i) System.out.print System.out System System.out " "+i " " i System.out.println() System.out.println System.out System System.out public static void main(String[]ag){
	new Main().main();
    } main {
	new Main().main();
    } new Main().main() new Main().main new Main() String[]ag ag
import java.util.*;
class Main{
    Scanner sc=new Scanner(System.in);
    void main(){
	int n=sc.nextInt();
	for(int i=1;i<=n;i++){
	    boolean e=false;
	    if(i%3==0)e=true;
	    for(int j=1;j<100000;j*=10)if(i/j%10==3)e=true;
	    if(e)System.out.print(" "+i);
	}
	System.out.println();
    }
    public static void main(String[]ag){
	new Main().main();
    }
}