import java.io.*;

public class Main{
	public static void main(String[] arsg) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int count = Integer.parseInt(br.readLine());
		for(int i = 1;i<=count;i++){
			if(i%3==0 || String.valueOf(i).contains("3")){System.out.print(" "+i);}
		}
		System.out.println();
	}
} import java.io.*; io.* java public class Main{
	public static void main(String[] arsg) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int count = Integer.parseInt(br.readLine());
		for(int i = 1;i<=count;i++){
			if(i%3==0 || String.valueOf(i).contains("3")){System.out.print(" "+i);}
		}
		System.out.println();
	}
} Main public static void main(String[] arsg) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int count = Integer.parseInt(br.readLine());
		for(int i = 1;i<=count;i++){
			if(i%3==0 || String.valueOf(i).contains("3")){System.out.print(" "+i);}
		}
		System.out.println();
	} main {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int count = Integer.parseInt(br.readLine());
		for(int i = 1;i<=count;i++){
			if(i%3==0 || String.valueOf(i).contains("3")){System.out.print(" "+i);}
		}
		System.out.println();
	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) int count = Integer.parseInt(br.readLine()); count Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br for(int i = 1;i<=count;i++){
			if(i%3==0 || String.valueOf(i).contains("3")){System.out.print(" "+i);}
		} int i = 1; int i = 1; i 1 i<=count i count i++ i++ i {
			if(i%3==0 || String.valueOf(i).contains("3")){System.out.print(" "+i);}
		} {
			if(i%3==0 || String.valueOf(i).contains("3")){System.out.print(" "+i);}
		} if(i%3==0 || String.valueOf(i).contains("3")){System.out.print(" "+i);} i%3==0 || String.valueOf(i).contains("3") i%3==0 i%3 i 3 0 String.valueOf(i).contains("3") String.valueOf(i).contains String.valueOf(i) String.valueOf String i "3" {System.out.print(" "+i);} 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 String[] arsg arsg public class Main{
	public static void main(String[] arsg) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int count = Integer.parseInt(br.readLine());
		for(int i = 1;i<=count;i++){
			if(i%3==0 || String.valueOf(i).contains("3")){System.out.print(" "+i);}
		}
		System.out.println();
	}
} public class Main{
	public static void main(String[] arsg) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int count = Integer.parseInt(br.readLine());
		for(int i = 1;i<=count;i++){
			if(i%3==0 || String.valueOf(i).contains("3")){System.out.print(" "+i);}
		}
		System.out.println();
	}
} Main
import java.io.*;

public class Main{
	public static void main(String[] arsg) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int count = Integer.parseInt(br.readLine());
		for(int i = 1;i<=count;i++){
			if(i%3==0 || String.valueOf(i).contains("3")){System.out.print(" "+i);}
		}
		System.out.println();
	}
}