import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Main{
	public static void main(String[]args)throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str;
		int n=0;
		
		while((str=br.readLine())!=null){
			n=Integer.parseInt(str);
			for(int i=1;i<=n;i++){
				int x=i;
				if(x%3==0){
					System.out.print(" "+i);
					continue;
				}
				do{
					if(x%10==3){
						System.out.print(" "+i);
						break;
					}
					x/=10;
				}while(x!=0);
			}
			System.out.print("\n");
			break;
		}
		br.close();
	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main{
	public static void main(String[]args)throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str;
		int n=0;
		
		while((str=br.readLine())!=null){
			n=Integer.parseInt(str);
			for(int i=1;i<=n;i++){
				int x=i;
				if(x%3==0){
					System.out.print(" "+i);
					continue;
				}
				do{
					if(x%10==3){
						System.out.print(" "+i);
						break;
					}
					x/=10;
				}while(x!=0);
			}
			System.out.print("\n");
			break;
		}
		br.close();
	}
} Main public static void main(String[]args)throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str;
		int n=0;
		
		while((str=br.readLine())!=null){
			n=Integer.parseInt(str);
			for(int i=1;i<=n;i++){
				int x=i;
				if(x%3==0){
					System.out.print(" "+i);
					continue;
				}
				do{
					if(x%10==3){
						System.out.print(" "+i);
						break;
					}
					x/=10;
				}while(x!=0);
			}
			System.out.print("\n");
			break;
		}
		br.close();
	} main {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str;
		int n=0;
		
		while((str=br.readLine())!=null){
			n=Integer.parseInt(str);
			for(int i=1;i<=n;i++){
				int x=i;
				if(x%3==0){
					System.out.print(" "+i);
					continue;
				}
				do{
					if(x%10==3){
						System.out.print(" "+i);
						break;
					}
					x/=10;
				}while(x!=0);
			}
			System.out.print("\n");
			break;
		}
		br.close();
	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String str; str int n=0; n 0 while((str=br.readLine())!=null){
			n=Integer.parseInt(str);
			for(int i=1;i<=n;i++){
				int x=i;
				if(x%3==0){
					System.out.print(" "+i);
					continue;
				}
				do{
					if(x%10==3){
						System.out.print(" "+i);
						break;
					}
					x/=10;
				}while(x!=0);
			}
			System.out.print("\n");
			break;
		} (str=br.readLine())!=null (str=br.readLine()) str br.readLine() br.readLine br null {
			n=Integer.parseInt(str);
			for(int i=1;i<=n;i++){
				int x=i;
				if(x%3==0){
					System.out.print(" "+i);
					continue;
				}
				do{
					if(x%10==3){
						System.out.print(" "+i);
						break;
					}
					x/=10;
				}while(x!=0);
			}
			System.out.print("\n");
			break;
		} n=Integer.parseInt(str) n Integer.parseInt(str) Integer.parseInt Integer str for(int i=1;i<=n;i++){
				int x=i;
				if(x%3==0){
					System.out.print(" "+i);
					continue;
				}
				do{
					if(x%10==3){
						System.out.print(" "+i);
						break;
					}
					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){
					System.out.print(" "+i);
					continue;
				}
				do{
					if(x%10==3){
						System.out.print(" "+i);
						break;
					}
					x/=10;
				}while(x!=0);
			} {
				int x=i;
				if(x%3==0){
					System.out.print(" "+i);
					continue;
				}
				do{
					if(x%10==3){
						System.out.print(" "+i);
						break;
					}
					x/=10;
				}while(x!=0);
			} int x=i; x i if(x%3==0){
					System.out.print(" "+i);
					continue;
				} x%3==0 x%3 x 3 0 {
					System.out.print(" "+i);
					continue;
				} System.out.print(" "+i) System.out.print System.out System System.out " "+i " " i continue; do{
					if(x%10==3){
						System.out.print(" "+i);
						break;
					}
					x/=10;
				}while(x!=0); 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 System.out.print("\n") System.out.print System.out System System.out "\n" break; br.close() br.close br String[]args args public class Main{
	public static void main(String[]args)throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str;
		int n=0;
		
		while((str=br.readLine())!=null){
			n=Integer.parseInt(str);
			for(int i=1;i<=n;i++){
				int x=i;
				if(x%3==0){
					System.out.print(" "+i);
					continue;
				}
				do{
					if(x%10==3){
						System.out.print(" "+i);
						break;
					}
					x/=10;
				}while(x!=0);
			}
			System.out.print("\n");
			break;
		}
		br.close();
	}
} public class Main{
	public static void main(String[]args)throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str;
		int n=0;
		
		while((str=br.readLine())!=null){
			n=Integer.parseInt(str);
			for(int i=1;i<=n;i++){
				int x=i;
				if(x%3==0){
					System.out.print(" "+i);
					continue;
				}
				do{
					if(x%10==3){
						System.out.print(" "+i);
						break;
					}
					x/=10;
				}while(x!=0);
			}
			System.out.print("\n");
			break;
		}
		br.close();
	}
} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Main{
	public static void main(String[]args)throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str;
		int n=0;
		
		while((str=br.readLine())!=null){
			n=Integer.parseInt(str);
			for(int i=1;i<=n;i++){
				int x=i;
				if(x%3==0){
					System.out.print(" "+i);
					continue;
				}
				do{
					if(x%10==3){
						System.out.print(" "+i);
						break;
					}
					x/=10;
				}while(x!=0);
			}
			System.out.print("\n");
			break;
		}
		br.close();
	}
}