import java.io.*;

class Main{
	public static void main(String args[]) throws IOException{
		BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(buf.readLine());
		StringBuilder sb = new StringBuilder();
		
		int num = 0;
		for(int j=3; j<=n; j++){
			if(j%3==0){
				sb.append(" "+j);
			} else {
				num = j;
				while(num != 0){
					if(num%10==3){
						sb.append(" "+j);
						break;
					} else{
						num = num/10;
					}	
				}
			}			

		}
		System.out.println(sb);
	}
} import java.io.*; io.* java class Main{
	public static void main(String args[]) throws IOException{
		BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(buf.readLine());
		StringBuilder sb = new StringBuilder();
		
		int num = 0;
		for(int j=3; j<=n; j++){
			if(j%3==0){
				sb.append(" "+j);
			} else {
				num = j;
				while(num != 0){
					if(num%10==3){
						sb.append(" "+j);
						break;
					} else{
						num = num/10;
					}	
				}
			}			

		}
		System.out.println(sb);
	}
} Main public static void main(String args[]) throws IOException{
		BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(buf.readLine());
		StringBuilder sb = new StringBuilder();
		
		int num = 0;
		for(int j=3; j<=n; j++){
			if(j%3==0){
				sb.append(" "+j);
			} else {
				num = j;
				while(num != 0){
					if(num%10==3){
						sb.append(" "+j);
						break;
					} else{
						num = num/10;
					}	
				}
			}			

		}
		System.out.println(sb);
	} main {
		BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(buf.readLine());
		StringBuilder sb = new StringBuilder();
		
		int num = 0;
		for(int j=3; j<=n; j++){
			if(j%3==0){
				sb.append(" "+j);
			} else {
				num = j;
				while(num != 0){
					if(num%10==3){
						sb.append(" "+j);
						break;
					} else{
						num = num/10;
					}	
				}
			}			

		}
		System.out.println(sb);
	} BufferedReader buf = new BufferedReader(new InputStreamReader(System.in)); buf new BufferedReader(new InputStreamReader(System.in)) int n = Integer.parseInt(buf.readLine()); n Integer.parseInt(buf.readLine()) Integer.parseInt Integer buf.readLine() buf.readLine buf StringBuilder sb = new StringBuilder(); sb new StringBuilder() int num = 0; num 0 for(int j=3; j<=n; j++){
			if(j%3==0){
				sb.append(" "+j);
			} else {
				num = j;
				while(num != 0){
					if(num%10==3){
						sb.append(" "+j);
						break;
					} else{
						num = num/10;
					}	
				}
			}			

		} int j=3; int j=3; j 3 j<=n j n j++ j++ j {
			if(j%3==0){
				sb.append(" "+j);
			} else {
				num = j;
				while(num != 0){
					if(num%10==3){
						sb.append(" "+j);
						break;
					} else{
						num = num/10;
					}	
				}
			}			

		} {
			if(j%3==0){
				sb.append(" "+j);
			} else {
				num = j;
				while(num != 0){
					if(num%10==3){
						sb.append(" "+j);
						break;
					} else{
						num = num/10;
					}	
				}
			}			

		} if(j%3==0){
				sb.append(" "+j);
			} else {
				num = j;
				while(num != 0){
					if(num%10==3){
						sb.append(" "+j);
						break;
					} else{
						num = num/10;
					}	
				}
			} j%3==0 j%3 j 3 0 {
				sb.append(" "+j);
			} sb.append(" "+j) sb.append sb " "+j " " j {
				num = j;
				while(num != 0){
					if(num%10==3){
						sb.append(" "+j);
						break;
					} else{
						num = num/10;
					}	
				}
			} num = j num j while(num != 0){
					if(num%10==3){
						sb.append(" "+j);
						break;
					} else{
						num = num/10;
					}	
				} num != 0 num 0 {
					if(num%10==3){
						sb.append(" "+j);
						break;
					} else{
						num = num/10;
					}	
				} if(num%10==3){
						sb.append(" "+j);
						break;
					} else{
						num = num/10;
					} num%10==3 num%10 num 10 3 {
						sb.append(" "+j);
						break;
					} sb.append(" "+j) sb.append sb " "+j " " j break; {
						num = num/10;
					} num = num/10 num num/10 num 10 System.out.println(sb) System.out.println System.out System System.out sb String args[] args
import java.io.*;

class Main{
	public static void main(String args[]) throws IOException{
		BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(buf.readLine());
		StringBuilder sb = new StringBuilder();
		
		int num = 0;
		for(int j=3; j<=n; j++){
			if(j%3==0){
				sb.append(" "+j);
			} else {
				num = j;
				while(num != 0){
					if(num%10==3){
						sb.append(" "+j);
						break;
					} else{
						num = num/10;
					}	
				}
			}			

		}
		System.out.println(sb);
	}
}