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 line = br.readLine();

		int N = Integer.parseInt(line);
		int x = 0;
		int i = 0;
		for(i = 3; i <= N; i++){
			x = i;
			if(x % 3 == 0){
				System.out.print(" "+i);
			}else{
				while(x!=0){
	                if(x%10==3){
	                    System.out.print(" " + i);
	                    break ; 
	                }
	                x = x/10; 
	            }
			}
		}
		System.out.printf("\n");
	}

} 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 line = br.readLine();

		int N = Integer.parseInt(line);
		int x = 0;
		int i = 0;
		for(i = 3; i <= N; i++){
			x = i;
			if(x % 3 == 0){
				System.out.print(" "+i);
			}else{
				while(x!=0){
	                if(x%10==3){
	                    System.out.print(" " + i);
	                    break ; 
	                }
	                x = x/10; 
	            }
			}
		}
		System.out.printf("\n");
	}

} Main public static void main(String[] args) throws Exception {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = br.readLine();

		int N = Integer.parseInt(line);
		int x = 0;
		int i = 0;
		for(i = 3; i <= N; i++){
			x = i;
			if(x % 3 == 0){
				System.out.print(" "+i);
			}else{
				while(x!=0){
	                if(x%10==3){
	                    System.out.print(" " + i);
	                    break ; 
	                }
	                x = x/10; 
	            }
			}
		}
		System.out.printf("\n");
	} main {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = br.readLine();

		int N = Integer.parseInt(line);
		int x = 0;
		int i = 0;
		for(i = 3; i <= N; i++){
			x = i;
			if(x % 3 == 0){
				System.out.print(" "+i);
			}else{
				while(x!=0){
	                if(x%10==3){
	                    System.out.print(" " + i);
	                    break ; 
	                }
	                x = x/10; 
	            }
			}
		}
		System.out.printf("\n");
	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String line = br.readLine(); line br.readLine() br.readLine br int N = Integer.parseInt(line); N Integer.parseInt(line) Integer.parseInt Integer line int x = 0; x 0 int i = 0; i 0 for(i = 3; i <= N; i++){
			x = i;
			if(x % 3 == 0){
				System.out.print(" "+i);
			}else{
				while(x!=0){
	                if(x%10==3){
	                    System.out.print(" " + i);
	                    break ; 
	                }
	                x = x/10; 
	            }
			}
		} i = 3; i = 3 i 3 i <= N i N i++ i++ i {
			x = i;
			if(x % 3 == 0){
				System.out.print(" "+i);
			}else{
				while(x!=0){
	                if(x%10==3){
	                    System.out.print(" " + i);
	                    break ; 
	                }
	                x = x/10; 
	            }
			}
		} {
			x = i;
			if(x % 3 == 0){
				System.out.print(" "+i);
			}else{
				while(x!=0){
	                if(x%10==3){
	                    System.out.print(" " + i);
	                    break ; 
	                }
	                x = x/10; 
	            }
			}
		} x = i x i if(x % 3 == 0){
				System.out.print(" "+i);
			}else{
				while(x!=0){
	                if(x%10==3){
	                    System.out.print(" " + i);
	                    break ; 
	                }
	                x = x/10; 
	            }
			} x % 3 == 0 x % 3 x 3 0 {
				System.out.print(" "+i);
			} System.out.print(" "+i) System.out.print System.out System System.out " "+i " " i {
				while(x!=0){
	                if(x%10==3){
	                    System.out.print(" " + i);
	                    break ; 
	                }
	                x = x/10; 
	            }
			} while(x!=0){
	                if(x%10==3){
	                    System.out.print(" " + i);
	                    break ; 
	                }
	                x = x/10; 
	            } x!=0 x 0 {
	                if(x%10==3){
	                    System.out.print(" " + i);
	                    break ; 
	                }
	                x = 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 = x/10 x x/10 x 10 System.out.printf("\n") System.out.printf System.out System System.out "\n" String[] args args public class Main {

	public static void main(String[] args) throws Exception {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = br.readLine();

		int N = Integer.parseInt(line);
		int x = 0;
		int i = 0;
		for(i = 3; i <= N; i++){
			x = i;
			if(x % 3 == 0){
				System.out.print(" "+i);
			}else{
				while(x!=0){
	                if(x%10==3){
	                    System.out.print(" " + i);
	                    break ; 
	                }
	                x = x/10; 
	            }
			}
		}
		System.out.printf("\n");
	}

} public class Main {

	public static void main(String[] args) throws Exception {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = br.readLine();

		int N = Integer.parseInt(line);
		int x = 0;
		int i = 0;
		for(i = 3; i <= N; i++){
			x = i;
			if(x % 3 == 0){
				System.out.print(" "+i);
			}else{
				while(x!=0){
	                if(x%10==3){
	                    System.out.print(" " + i);
	                    break ; 
	                }
	                x = x/10; 
	            }
			}
		}
		System.out.printf("\n");
	}

} 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 line = br.readLine();

		int N = Integer.parseInt(line);
		int x = 0;
		int i = 0;
		for(i = 3; i <= N; i++){
			x = i;
			if(x % 3 == 0){
				System.out.print(" "+i);
			}else{
				while(x!=0){
	                if(x%10==3){
	                    System.out.print(" " + i);
	                    break ; 
	                }
	                x = x/10; 
	            }
			}
		}
		System.out.printf("\n");
	}

}