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));
		StringBuilder sb = new StringBuilder();
		
		String line = br.readLine();
		int n =  Integer.parseInt(line);
		int i = 0;
		for(int j=3; j<=n; j++){
			if(j % 3 ==0){
				sb.append(" ").append(j);
			}
			else{
				i = j;
				while(i != 0){
					if(i % 10 == 3){
						sb.append(" ").append(j);
						break;
					}
					else{
						i = i / 10;
					}
				}
			}
		}
		System.out.println(sb);
	}
} 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));
		StringBuilder sb = new StringBuilder();
		
		String line = br.readLine();
		int n =  Integer.parseInt(line);
		int i = 0;
		for(int j=3; j<=n; j++){
			if(j % 3 ==0){
				sb.append(" ").append(j);
			}
			else{
				i = j;
				while(i != 0){
					if(i % 10 == 3){
						sb.append(" ").append(j);
						break;
					}
					else{
						i = i / 10;
					}
				}
			}
		}
		System.out.println(sb);
	}
} Main public static void main(String[] args)throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();
		
		String line = br.readLine();
		int n =  Integer.parseInt(line);
		int i = 0;
		for(int j=3; j<=n; j++){
			if(j % 3 ==0){
				sb.append(" ").append(j);
			}
			else{
				i = j;
				while(i != 0){
					if(i % 10 == 3){
						sb.append(" ").append(j);
						break;
					}
					else{
						i = i / 10;
					}
				}
			}
		}
		System.out.println(sb);
	} main {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();
		
		String line = br.readLine();
		int n =  Integer.parseInt(line);
		int i = 0;
		for(int j=3; j<=n; j++){
			if(j % 3 ==0){
				sb.append(" ").append(j);
			}
			else{
				i = j;
				while(i != 0){
					if(i % 10 == 3){
						sb.append(" ").append(j);
						break;
					}
					else{
						i = i / 10;
					}
				}
			}
		}
		System.out.println(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 int i = 0; i 0 for(int j=3; j<=n; j++){
			if(j % 3 ==0){
				sb.append(" ").append(j);
			}
			else{
				i = j;
				while(i != 0){
					if(i % 10 == 3){
						sb.append(" ").append(j);
						break;
					}
					else{
						i = i / 10;
					}
				}
			}
		} int j=3; int j=3; j 3 j<=n j n j++ j++ j {
			if(j % 3 ==0){
				sb.append(" ").append(j);
			}
			else{
				i = j;
				while(i != 0){
					if(i % 10 == 3){
						sb.append(" ").append(j);
						break;
					}
					else{
						i = i / 10;
					}
				}
			}
		} {
			if(j % 3 ==0){
				sb.append(" ").append(j);
			}
			else{
				i = j;
				while(i != 0){
					if(i % 10 == 3){
						sb.append(" ").append(j);
						break;
					}
					else{
						i = i / 10;
					}
				}
			}
		} if(j % 3 ==0){
				sb.append(" ").append(j);
			}
			else{
				i = j;
				while(i != 0){
					if(i % 10 == 3){
						sb.append(" ").append(j);
						break;
					}
					else{
						i = i / 10;
					}
				}
			} j % 3 ==0 j % 3 j 3 0 {
				sb.append(" ").append(j);
			} sb.append(" ").append(j) sb.append(" ").append sb.append(" ") sb.append sb " " j {
				i = j;
				while(i != 0){
					if(i % 10 == 3){
						sb.append(" ").append(j);
						break;
					}
					else{
						i = i / 10;
					}
				}
			} i = j i j while(i != 0){
					if(i % 10 == 3){
						sb.append(" ").append(j);
						break;
					}
					else{
						i = i / 10;
					}
				} i != 0 i 0 {
					if(i % 10 == 3){
						sb.append(" ").append(j);
						break;
					}
					else{
						i = i / 10;
					}
				} if(i % 10 == 3){
						sb.append(" ").append(j);
						break;
					}
					else{
						i = i / 10;
					} i % 10 == 3 i % 10 i 10 3 {
						sb.append(" ").append(j);
						break;
					} sb.append(" ").append(j) sb.append(" ").append sb.append(" ") sb.append sb " " j break; {
						i = i / 10;
					} i = i / 10 i i / 10 i 10 System.out.println(sb) System.out.println System.out System System.out sb String[] args args public class Main{
	
	public static void main(String[] args)throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();
		
		String line = br.readLine();
		int n =  Integer.parseInt(line);
		int i = 0;
		for(int j=3; j<=n; j++){
			if(j % 3 ==0){
				sb.append(" ").append(j);
			}
			else{
				i = j;
				while(i != 0){
					if(i % 10 == 3){
						sb.append(" ").append(j);
						break;
					}
					else{
						i = i / 10;
					}
				}
			}
		}
		System.out.println(sb);
	}
} public class Main{
	
	public static void main(String[] args)throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();
		
		String line = br.readLine();
		int n =  Integer.parseInt(line);
		int i = 0;
		for(int j=3; j<=n; j++){
			if(j % 3 ==0){
				sb.append(" ").append(j);
			}
			else{
				i = j;
				while(i != 0){
					if(i % 10 == 3){
						sb.append(" ").append(j);
						break;
					}
					else{
						i = i / 10;
					}
				}
			}
		}
		System.out.println(sb);
	}
} 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));
		StringBuilder sb = new StringBuilder();
		
		String line = br.readLine();
		int n =  Integer.parseInt(line);
		int i = 0;
		for(int j=3; j<=n; j++){
			if(j % 3 ==0){
				sb.append(" ").append(j);
			}
			else{
				i = j;
				while(i != 0){
					if(i % 10 == 3){
						sb.append(" ").append(j);
						break;
					}
					else{
						i = i / 10;
					}
				}
			}
		}
		System.out.println(sb);
	}
}