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