import java.io.*;
  
class Main{
	public static void main(String[] args) throws IOException{
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int x = Integer.parseInt(br.readLine());
		StringBuilder sb = new StringBuilder();

		for(int i = 2; i < x+1; i++){
			String s = String.valueOf(i);
			if(i%3 == 0){
				sb.append(" " + i);
			}else {
				for (int k = 0; k < s.length(); k++){
                    			if (s.indexOf('3') != -1){
                        			sb.append(" " + i);
                        			break;
					}
				}
			}
		}
		System.out.println(sb.toString());
  	}
} import java.io.*; io.* java class Main{
	public static void main(String[] args) throws IOException{
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int x = Integer.parseInt(br.readLine());
		StringBuilder sb = new StringBuilder();

		for(int i = 2; i < x+1; i++){
			String s = String.valueOf(i);
			if(i%3 == 0){
				sb.append(" " + i);
			}else {
				for (int k = 0; k < s.length(); k++){
                    			if (s.indexOf('3') != -1){
                        			sb.append(" " + i);
                        			break;
					}
				}
			}
		}
		System.out.println(sb.toString());
  	}
} Main public static void main(String[] args) throws IOException{
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int x = Integer.parseInt(br.readLine());
		StringBuilder sb = new StringBuilder();

		for(int i = 2; i < x+1; i++){
			String s = String.valueOf(i);
			if(i%3 == 0){
				sb.append(" " + i);
			}else {
				for (int k = 0; k < s.length(); k++){
                    			if (s.indexOf('3') != -1){
                        			sb.append(" " + i);
                        			break;
					}
				}
			}
		}
		System.out.println(sb.toString());
  	} main {
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int x = Integer.parseInt(br.readLine());
		StringBuilder sb = new StringBuilder();

		for(int i = 2; i < x+1; i++){
			String s = String.valueOf(i);
			if(i%3 == 0){
				sb.append(" " + i);
			}else {
				for (int k = 0; k < s.length(); k++){
                    			if (s.indexOf('3') != -1){
                        			sb.append(" " + i);
                        			break;
					}
				}
			}
		}
		System.out.println(sb.toString());
  	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) int x = Integer.parseInt(br.readLine()); x Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br StringBuilder sb = new StringBuilder(); sb new StringBuilder() for(int i = 2; i < x+1; i++){
			String s = String.valueOf(i);
			if(i%3 == 0){
				sb.append(" " + i);
			}else {
				for (int k = 0; k < s.length(); k++){
                    			if (s.indexOf('3') != -1){
                        			sb.append(" " + i);
                        			break;
					}
				}
			}
		} int i = 2; int i = 2; i 2 i < x+1 i x+1 x 1 i++ i++ i {
			String s = String.valueOf(i);
			if(i%3 == 0){
				sb.append(" " + i);
			}else {
				for (int k = 0; k < s.length(); k++){
                    			if (s.indexOf('3') != -1){
                        			sb.append(" " + i);
                        			break;
					}
				}
			}
		} {
			String s = String.valueOf(i);
			if(i%3 == 0){
				sb.append(" " + i);
			}else {
				for (int k = 0; k < s.length(); k++){
                    			if (s.indexOf('3') != -1){
                        			sb.append(" " + i);
                        			break;
					}
				}
			}
		} String s = String.valueOf(i); s String.valueOf(i) String.valueOf String i if(i%3 == 0){
				sb.append(" " + i);
			}else {
				for (int k = 0; k < s.length(); k++){
                    			if (s.indexOf('3') != -1){
                        			sb.append(" " + i);
                        			break;
					}
				}
			} i%3 == 0 i%3 i 3 0 {
				sb.append(" " + i);
			} sb.append(" " + i) sb.append sb " " + i " " i {
				for (int k = 0; k < s.length(); k++){
                    			if (s.indexOf('3') != -1){
                        			sb.append(" " + i);
                        			break;
					}
				}
			} for (int k = 0; k < s.length(); k++){
                    			if (s.indexOf('3') != -1){
                        			sb.append(" " + i);
                        			break;
					}
				} int k = 0; int k = 0; k 0 k < s.length() k s.length() s.length s k++ k++ k {
                    			if (s.indexOf('3') != -1){
                        			sb.append(" " + i);
                        			break;
					}
				} {
                    			if (s.indexOf('3') != -1){
                        			sb.append(" " + i);
                        			break;
					}
				} if (s.indexOf('3') != -1){
                        			sb.append(" " + i);
                        			break;
					} s.indexOf('3') != -1 s.indexOf('3') s.indexOf s '3' -1 1 {
                        			sb.append(" " + i);
                        			break;
					} sb.append(" " + i) sb.append sb " " + i " " i break; System.out.println(sb.toString()) System.out.println System.out System System.out sb.toString() sb.toString sb String[] args args
import java.io.*;
  
class Main{
	public static void main(String[] args) throws IOException{
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int x = Integer.parseInt(br.readLine());
		StringBuilder sb = new StringBuilder();

		for(int i = 2; i < x+1; i++){
			String s = String.valueOf(i);
			if(i%3 == 0){
				sb.append(" " + i);
			}else {
				for (int k = 0; k < s.length(); k++){
                    			if (s.indexOf('3') != -1){
                        			sb.append(" " + i);
                        			break;
					}
				}
			}
		}
		System.out.println(sb.toString());
  	}
}