import java.util.Scanner;

/**
 * @author kawakami
 *
 */
class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner as = new Scanner(System.in);
		
		int n=as.nextInt();
		int i=1;
		String str;
		
		while(true){
			int x=i;
			if(x % 3 == 0){
				str=" "+String.valueOf(i);
				System.out.print(str);
			
			}
			
			else if(x % 10 == 3){
				str=" "+String.valueOf(i);
				System.out.print(str);
			}
			
			else{
				while(true){
					x=x/10;
					if(x == 0){
						break;
					}
				
				
					if(x % 10 == 3){
						str=" "+String.valueOf(i);
						System.out.print(str);
						break;
					}
					
					
				
				}
				
			}
				 
			
			if(i++ >= n){
				System.out.println();
				break;
			}
			
		}
		
		
		
		
		
			

	}

} import java.util.Scanner; Scanner java.util class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner as = new Scanner(System.in);
		
		int n=as.nextInt();
		int i=1;
		String str;
		
		while(true){
			int x=i;
			if(x % 3 == 0){
				str=" "+String.valueOf(i);
				System.out.print(str);
			
			}
			
			else if(x % 10 == 3){
				str=" "+String.valueOf(i);
				System.out.print(str);
			}
			
			else{
				while(true){
					x=x/10;
					if(x == 0){
						break;
					}
				
				
					if(x % 10 == 3){
						str=" "+String.valueOf(i);
						System.out.print(str);
						break;
					}
					
					
				
				}
				
			}
				 
			
			if(i++ >= n){
				System.out.println();
				break;
			}
			
		}
		
		
		
		
		
			

	}

} Main /**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner as = new Scanner(System.in);
		
		int n=as.nextInt();
		int i=1;
		String str;
		
		while(true){
			int x=i;
			if(x % 3 == 0){
				str=" "+String.valueOf(i);
				System.out.print(str);
			
			}
			
			else if(x % 10 == 3){
				str=" "+String.valueOf(i);
				System.out.print(str);
			}
			
			else{
				while(true){
					x=x/10;
					if(x == 0){
						break;
					}
				
				
					if(x % 10 == 3){
						str=" "+String.valueOf(i);
						System.out.print(str);
						break;
					}
					
					
				
				}
				
			}
				 
			
			if(i++ >= n){
				System.out.println();
				break;
			}
			
		}
		
		
		
		
		
			

	} main {
		// TODO Auto-generated method stub
		Scanner as = new Scanner(System.in);
		
		int n=as.nextInt();
		int i=1;
		String str;
		
		while(true){
			int x=i;
			if(x % 3 == 0){
				str=" "+String.valueOf(i);
				System.out.print(str);
			
			}
			
			else if(x % 10 == 3){
				str=" "+String.valueOf(i);
				System.out.print(str);
			}
			
			else{
				while(true){
					x=x/10;
					if(x == 0){
						break;
					}
				
				
					if(x % 10 == 3){
						str=" "+String.valueOf(i);
						System.out.print(str);
						break;
					}
					
					
				
				}
				
			}
				 
			
			if(i++ >= n){
				System.out.println();
				break;
			}
			
		}
		
		
		
		
		
			

	} Scanner as = new Scanner(System.in); as new Scanner(System.in) int n=as.nextInt(); n as.nextInt() as.nextInt as int i=1; i 1 String str; str while(true){
			int x=i;
			if(x % 3 == 0){
				str=" "+String.valueOf(i);
				System.out.print(str);
			
			}
			
			else if(x % 10 == 3){
				str=" "+String.valueOf(i);
				System.out.print(str);
			}
			
			else{
				while(true){
					x=x/10;
					if(x == 0){
						break;
					}
				
				
					if(x % 10 == 3){
						str=" "+String.valueOf(i);
						System.out.print(str);
						break;
					}
					
					
				
				}
				
			}
				 
			
			if(i++ >= n){
				System.out.println();
				break;
			}
			
		} true {
			int x=i;
			if(x % 3 == 0){
				str=" "+String.valueOf(i);
				System.out.print(str);
			
			}
			
			else if(x % 10 == 3){
				str=" "+String.valueOf(i);
				System.out.print(str);
			}
			
			else{
				while(true){
					x=x/10;
					if(x == 0){
						break;
					}
				
				
					if(x % 10 == 3){
						str=" "+String.valueOf(i);
						System.out.print(str);
						break;
					}
					
					
				
				}
				
			}
				 
			
			if(i++ >= n){
				System.out.println();
				break;
			}
			
		} int x=i; x i if(x % 3 == 0){
				str=" "+String.valueOf(i);
				System.out.print(str);
			
			}
			
			else if(x % 10 == 3){
				str=" "+String.valueOf(i);
				System.out.print(str);
			}
			
			else{
				while(true){
					x=x/10;
					if(x == 0){
						break;
					}
				
				
					if(x % 10 == 3){
						str=" "+String.valueOf(i);
						System.out.print(str);
						break;
					}
					
					
				
				}
				
			} x % 3 == 0 x % 3 x 3 0 {
				str=" "+String.valueOf(i);
				System.out.print(str);
			
			} str=" "+String.valueOf(i) str " "+String.valueOf(i) " " String.valueOf(i) String.valueOf String i System.out.print(str) System.out.print System.out System System.out str if(x % 10 == 3){
				str=" "+String.valueOf(i);
				System.out.print(str);
			}
			
			else{
				while(true){
					x=x/10;
					if(x == 0){
						break;
					}
				
				
					if(x % 10 == 3){
						str=" "+String.valueOf(i);
						System.out.print(str);
						break;
					}
					
					
				
				}
				
			} x % 10 == 3 x % 10 x 10 3 {
				str=" "+String.valueOf(i);
				System.out.print(str);
			} str=" "+String.valueOf(i) str " "+String.valueOf(i) " " String.valueOf(i) String.valueOf String i System.out.print(str) System.out.print System.out System System.out str {
				while(true){
					x=x/10;
					if(x == 0){
						break;
					}
				
				
					if(x % 10 == 3){
						str=" "+String.valueOf(i);
						System.out.print(str);
						break;
					}
					
					
				
				}
				
			} while(true){
					x=x/10;
					if(x == 0){
						break;
					}
				
				
					if(x % 10 == 3){
						str=" "+String.valueOf(i);
						System.out.print(str);
						break;
					}
					
					
				
				} true {
					x=x/10;
					if(x == 0){
						break;
					}
				
				
					if(x % 10 == 3){
						str=" "+String.valueOf(i);
						System.out.print(str);
						break;
					}
					
					
				
				} x=x/10 x x/10 x 10 if(x == 0){
						break;
					} x == 0 x 0 {
						break;
					} break; if(x % 10 == 3){
						str=" "+String.valueOf(i);
						System.out.print(str);
						break;
					} x % 10 == 3 x % 10 x 10 3 {
						str=" "+String.valueOf(i);
						System.out.print(str);
						break;
					} str=" "+String.valueOf(i) str " "+String.valueOf(i) " " String.valueOf(i) String.valueOf String i System.out.print(str) System.out.print System.out System System.out str break; if(i++ >= n){
				System.out.println();
				break;
			} i++ >= n i++ i n {
				System.out.println();
				break;
			} System.out.println() System.out.println System.out System System.out break; String[] args args
import java.util.Scanner;

/**
 * @author kawakami
 *
 */
class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner as = new Scanner(System.in);
		
		int n=as.nextInt();
		int i=1;
		String str;
		
		while(true){
			int x=i;
			if(x % 3 == 0){
				str=" "+String.valueOf(i);
				System.out.print(str);
			
			}
			
			else if(x % 10 == 3){
				str=" "+String.valueOf(i);
				System.out.print(str);
			}
			
			else{
				while(true){
					x=x/10;
					if(x == 0){
						break;
					}
				
				
					if(x % 10 == 3){
						str=" "+String.valueOf(i);
						System.out.print(str);
						break;
					}
					
					
				
				}
				
			}
				 
			
			if(i++ >= n){
				System.out.println();
				break;
			}
			
		}
		
		
		
		
		
			

	}

}