import java.io.*;
import java.util.Arrays;
class Main{
	public static void main(String[] args) throws IOException {
		int i,tmp;
		int[] n = new int[990];
		String[] str = new String[990];
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		str = in.readLine().split(" ");
		for(i=0;i<1;i++){
			n[i] = Integer.parseInt(str[i]);
		}
		for(i=3;i<=n[0];i++){
			tmp = i;
			if(tmp%3==0){
				System.out.print(" "+i);
				continue;
			}
			else{
				while(tmp!=0){
					if(tmp%10==3){
						System.out.print(" "+i);
						break;
					}
					tmp/=10;
				}
			}
		} 
		System.out.println();
		System.out.flush();
	}
} import java.io.*; io.* java import java.util.Arrays; Arrays java.util class Main{
	public static void main(String[] args) throws IOException {
		int i,tmp;
		int[] n = new int[990];
		String[] str = new String[990];
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		str = in.readLine().split(" ");
		for(i=0;i<1;i++){
			n[i] = Integer.parseInt(str[i]);
		}
		for(i=3;i<=n[0];i++){
			tmp = i;
			if(tmp%3==0){
				System.out.print(" "+i);
				continue;
			}
			else{
				while(tmp!=0){
					if(tmp%10==3){
						System.out.print(" "+i);
						break;
					}
					tmp/=10;
				}
			}
		} 
		System.out.println();
		System.out.flush();
	}
} Main public static void main(String[] args) throws IOException {
		int i,tmp;
		int[] n = new int[990];
		String[] str = new String[990];
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		str = in.readLine().split(" ");
		for(i=0;i<1;i++){
			n[i] = Integer.parseInt(str[i]);
		}
		for(i=3;i<=n[0];i++){
			tmp = i;
			if(tmp%3==0){
				System.out.print(" "+i);
				continue;
			}
			else{
				while(tmp!=0){
					if(tmp%10==3){
						System.out.print(" "+i);
						break;
					}
					tmp/=10;
				}
			}
		} 
		System.out.println();
		System.out.flush();
	} main {
		int i,tmp;
		int[] n = new int[990];
		String[] str = new String[990];
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		str = in.readLine().split(" ");
		for(i=0;i<1;i++){
			n[i] = Integer.parseInt(str[i]);
		}
		for(i=3;i<=n[0];i++){
			tmp = i;
			if(tmp%3==0){
				System.out.print(" "+i);
				continue;
			}
			else{
				while(tmp!=0){
					if(tmp%10==3){
						System.out.print(" "+i);
						break;
					}
					tmp/=10;
				}
			}
		} 
		System.out.println();
		System.out.flush();
	} int i i tmp; tmp int[] n = new int[990]; n new int[990] 990 String[] str = new String[990]; str new String[990] 990 BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); in new BufferedReader(new InputStreamReader(System.in)) str = in.readLine().split(" ") str in.readLine().split(" ") in.readLine().split in.readLine() in.readLine in " " for(i=0;i<1;i++){
			n[i] = Integer.parseInt(str[i]);
		} i=0; i=0 i 0 i<1 i 1 i++ i++ i {
			n[i] = Integer.parseInt(str[i]);
		} {
			n[i] = Integer.parseInt(str[i]);
		} n[i] = Integer.parseInt(str[i]) n[i] n i Integer.parseInt(str[i]) Integer.parseInt Integer str[i] str i for(i=3;i<=n[0];i++){
			tmp = i;
			if(tmp%3==0){
				System.out.print(" "+i);
				continue;
			}
			else{
				while(tmp!=0){
					if(tmp%10==3){
						System.out.print(" "+i);
						break;
					}
					tmp/=10;
				}
			}
		} i=3; i=3 i 3 i<=n[0] i n[0] n 0 i++ i++ i {
			tmp = i;
			if(tmp%3==0){
				System.out.print(" "+i);
				continue;
			}
			else{
				while(tmp!=0){
					if(tmp%10==3){
						System.out.print(" "+i);
						break;
					}
					tmp/=10;
				}
			}
		} {
			tmp = i;
			if(tmp%3==0){
				System.out.print(" "+i);
				continue;
			}
			else{
				while(tmp!=0){
					if(tmp%10==3){
						System.out.print(" "+i);
						break;
					}
					tmp/=10;
				}
			}
		} tmp = i tmp i if(tmp%3==0){
				System.out.print(" "+i);
				continue;
			}
			else{
				while(tmp!=0){
					if(tmp%10==3){
						System.out.print(" "+i);
						break;
					}
					tmp/=10;
				}
			} tmp%3==0 tmp%3 tmp 3 0 {
				System.out.print(" "+i);
				continue;
			} System.out.print(" "+i) System.out.print System.out System System.out " "+i " " i continue; {
				while(tmp!=0){
					if(tmp%10==3){
						System.out.print(" "+i);
						break;
					}
					tmp/=10;
				}
			} while(tmp!=0){
					if(tmp%10==3){
						System.out.print(" "+i);
						break;
					}
					tmp/=10;
				} tmp!=0 tmp 0 {
					if(tmp%10==3){
						System.out.print(" "+i);
						break;
					}
					tmp/=10;
				} if(tmp%10==3){
						System.out.print(" "+i);
						break;
					} tmp%10==3 tmp%10 tmp 10 3 {
						System.out.print(" "+i);
						break;
					} System.out.print(" "+i) System.out.print System.out System System.out " "+i " " i break; tmp/=10 tmp 10 System.out.println() System.out.println System.out System System.out System.out.flush() System.out.flush System.out System System.out String[] args args
import java.io.*;
import java.util.Arrays;
class Main{
	public static void main(String[] args) throws IOException {
		int i,tmp;
		int[] n = new int[990];
		String[] str = new String[990];
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		str = in.readLine().split(" ");
		for(i=0;i<1;i++){
			n[i] = Integer.parseInt(str[i]);
		}
		for(i=3;i<=n[0];i++){
			tmp = i;
			if(tmp%3==0){
				System.out.print(" "+i);
				continue;
			}
			else{
				while(tmp!=0){
					if(tmp%10==3){
						System.out.print(" "+i);
						break;
					}
					tmp/=10;
				}
			}
		} 
		System.out.println();
		System.out.flush();
	}
}