import java.io.*;

class Main{
	
	public static void main(String args[]) throws IOException{
		BufferedReader br 
			= new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());
		
		int i=1;
		int x;
		while(true){
			x = i;
			
			if(x%3==0){
				System.out.print(" "+i);
			} else {
			
				while(x != 0){
					if(x%10==3){
						System.out.print(" "+i);
						break;
					}
					
					x/=10;
				}
				
			} 
			
			if(++i > n)break;
		}
		
		System.out.print("\n");
	}
	
} import java.io.*; io.* java class Main{
	
	public static void main(String args[]) throws IOException{
		BufferedReader br 
			= new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());
		
		int i=1;
		int x;
		while(true){
			x = i;
			
			if(x%3==0){
				System.out.print(" "+i);
			} else {
			
				while(x != 0){
					if(x%10==3){
						System.out.print(" "+i);
						break;
					}
					
					x/=10;
				}
				
			} 
			
			if(++i > n)break;
		}
		
		System.out.print("\n");
	}
	
} Main public static void main(String args[]) throws IOException{
		BufferedReader br 
			= new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());
		
		int i=1;
		int x;
		while(true){
			x = i;
			
			if(x%3==0){
				System.out.print(" "+i);
			} else {
			
				while(x != 0){
					if(x%10==3){
						System.out.print(" "+i);
						break;
					}
					
					x/=10;
				}
				
			} 
			
			if(++i > n)break;
		}
		
		System.out.print("\n");
	} main {
		BufferedReader br 
			= new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());
		
		int i=1;
		int x;
		while(true){
			x = i;
			
			if(x%3==0){
				System.out.print(" "+i);
			} else {
			
				while(x != 0){
					if(x%10==3){
						System.out.print(" "+i);
						break;
					}
					
					x/=10;
				}
				
			} 
			
			if(++i > n)break;
		}
		
		System.out.print("\n");
	} BufferedReader br 
			= new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) int n = Integer.parseInt(br.readLine()); n Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br int i=1; i 1 int x; x while(true){
			x = i;
			
			if(x%3==0){
				System.out.print(" "+i);
			} else {
			
				while(x != 0){
					if(x%10==3){
						System.out.print(" "+i);
						break;
					}
					
					x/=10;
				}
				
			} 
			
			if(++i > n)break;
		} true {
			x = i;
			
			if(x%3==0){
				System.out.print(" "+i);
			} else {
			
				while(x != 0){
					if(x%10==3){
						System.out.print(" "+i);
						break;
					}
					
					x/=10;
				}
				
			} 
			
			if(++i > n)break;
		} x = i x i if(x%3==0){
				System.out.print(" "+i);
			} else {
			
				while(x != 0){
					if(x%10==3){
						System.out.print(" "+i);
						break;
					}
					
					x/=10;
				}
				
			} x%3==0 x%3 x 3 0 {
				System.out.print(" "+i);
			} System.out.print(" "+i) System.out.print System.out System System.out " "+i " " i {
			
				while(x != 0){
					if(x%10==3){
						System.out.print(" "+i);
						break;
					}
					
					x/=10;
				}
				
			} while(x != 0){
					if(x%10==3){
						System.out.print(" "+i);
						break;
					}
					
					x/=10;
				} x != 0 x 0 {
					if(x%10==3){
						System.out.print(" "+i);
						break;
					}
					
					x/=10;
				} if(x%10==3){
						System.out.print(" "+i);
						break;
					} x%10==3 x%10 x 10 3 {
						System.out.print(" "+i);
						break;
					} System.out.print(" "+i) System.out.print System.out System System.out " "+i " " i break; x/=10 x 10 if(++i > n)break; ++i > n ++i i n break; System.out.print("\n") System.out.print System.out System System.out "\n" String args[] args
import java.io.*;

class Main{
	
	public static void main(String args[]) throws IOException{
		BufferedReader br 
			= new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());
		
		int i=1;
		int x;
		while(true){
			x = i;
			
			if(x%3==0){
				System.out.print(" "+i);
			} else {
			
				while(x != 0){
					if(x%10==3){
						System.out.print(" "+i);
						break;
					}
					
					x/=10;
				}
				
			} 
			
			if(++i > n)break;
		}
		
		System.out.print("\n");
	}
	
}