import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		int inputData = Integer.parseInt(in.readLine());
		StringBuilder sb = new StringBuilder();
		String str;

		for (int i = 1; i <= inputData; i++) {
			if (i % 3 == 0) {
				sb.append(" " + i);
			} else if (i % 10 == 3) {
				sb.append(" " + i);
			} else {
				str = Integer.toString(i);
				char[] ch = str.toCharArray();
				for (int j = 0; j < ch.length; j++) {
					if (ch[j] == '3') {
						sb.append(" " + i);
                                                break;
					}
				}
			}
		}
		System.out.println(sb.toString());
	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		int inputData = Integer.parseInt(in.readLine());
		StringBuilder sb = new StringBuilder();
		String str;

		for (int i = 1; i <= inputData; i++) {
			if (i % 3 == 0) {
				sb.append(" " + i);
			} else if (i % 10 == 3) {
				sb.append(" " + i);
			} else {
				str = Integer.toString(i);
				char[] ch = str.toCharArray();
				for (int j = 0; j < ch.length; j++) {
					if (ch[j] == '3') {
						sb.append(" " + i);
                                                break;
					}
				}
			}
		}
		System.out.println(sb.toString());
	}
} Main public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		int inputData = Integer.parseInt(in.readLine());
		StringBuilder sb = new StringBuilder();
		String str;

		for (int i = 1; i <= inputData; i++) {
			if (i % 3 == 0) {
				sb.append(" " + i);
			} else if (i % 10 == 3) {
				sb.append(" " + i);
			} else {
				str = Integer.toString(i);
				char[] ch = str.toCharArray();
				for (int j = 0; j < ch.length; j++) {
					if (ch[j] == '3') {
						sb.append(" " + i);
                                                break;
					}
				}
			}
		}
		System.out.println(sb.toString());
	} main {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		int inputData = Integer.parseInt(in.readLine());
		StringBuilder sb = new StringBuilder();
		String str;

		for (int i = 1; i <= inputData; i++) {
			if (i % 3 == 0) {
				sb.append(" " + i);
			} else if (i % 10 == 3) {
				sb.append(" " + i);
			} else {
				str = Integer.toString(i);
				char[] ch = str.toCharArray();
				for (int j = 0; j < ch.length; j++) {
					if (ch[j] == '3') {
						sb.append(" " + i);
                                                break;
					}
				}
			}
		}
		System.out.println(sb.toString());
	} BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); in new BufferedReader(new InputStreamReader(System.in)) int inputData = Integer.parseInt(in.readLine()); inputData Integer.parseInt(in.readLine()) Integer.parseInt Integer in.readLine() in.readLine in StringBuilder sb = new StringBuilder(); sb new StringBuilder() String str; str for (int i = 1; i <= inputData; i++) {
			if (i % 3 == 0) {
				sb.append(" " + i);
			} else if (i % 10 == 3) {
				sb.append(" " + i);
			} else {
				str = Integer.toString(i);
				char[] ch = str.toCharArray();
				for (int j = 0; j < ch.length; j++) {
					if (ch[j] == '3') {
						sb.append(" " + i);
                                                break;
					}
				}
			}
		} int i = 1; int i = 1; i 1 i <= inputData i inputData i++ i++ i {
			if (i % 3 == 0) {
				sb.append(" " + i);
			} else if (i % 10 == 3) {
				sb.append(" " + i);
			} else {
				str = Integer.toString(i);
				char[] ch = str.toCharArray();
				for (int j = 0; j < ch.length; j++) {
					if (ch[j] == '3') {
						sb.append(" " + i);
                                                break;
					}
				}
			}
		} {
			if (i % 3 == 0) {
				sb.append(" " + i);
			} else if (i % 10 == 3) {
				sb.append(" " + i);
			} else {
				str = Integer.toString(i);
				char[] ch = str.toCharArray();
				for (int j = 0; j < ch.length; j++) {
					if (ch[j] == '3') {
						sb.append(" " + i);
                                                break;
					}
				}
			}
		} if (i % 3 == 0) {
				sb.append(" " + i);
			} else if (i % 10 == 3) {
				sb.append(" " + i);
			} else {
				str = Integer.toString(i);
				char[] ch = str.toCharArray();
				for (int j = 0; j < ch.length; j++) {
					if (ch[j] == '3') {
						sb.append(" " + i);
                                                break;
					}
				}
			} i % 3 == 0 i % 3 i 3 0 {
				sb.append(" " + i);
			} sb.append(" " + i) sb.append sb " " + i " " i if (i % 10 == 3) {
				sb.append(" " + i);
			} else {
				str = Integer.toString(i);
				char[] ch = str.toCharArray();
				for (int j = 0; j < ch.length; j++) {
					if (ch[j] == '3') {
						sb.append(" " + i);
                                                break;
					}
				}
			} i % 10 == 3 i % 10 i 10 3 {
				sb.append(" " + i);
			} sb.append(" " + i) sb.append sb " " + i " " i {
				str = Integer.toString(i);
				char[] ch = str.toCharArray();
				for (int j = 0; j < ch.length; j++) {
					if (ch[j] == '3') {
						sb.append(" " + i);
                                                break;
					}
				}
			} str = Integer.toString(i) str Integer.toString(i) Integer.toString Integer i char[] ch = str.toCharArray(); ch str.toCharArray() str.toCharArray str for (int j = 0; j < ch.length; j++) {
					if (ch[j] == '3') {
						sb.append(" " + i);
                                                break;
					}
				} int j = 0; int j = 0; j 0 j < ch.length j ch.length ch ch.length j++ j++ j {
					if (ch[j] == '3') {
						sb.append(" " + i);
                                                break;
					}
				} {
					if (ch[j] == '3') {
						sb.append(" " + i);
                                                break;
					}
				} if (ch[j] == '3') {
						sb.append(" " + i);
                                                break;
					} ch[j] == '3' ch[j] ch j '3' {
						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 public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		int inputData = Integer.parseInt(in.readLine());
		StringBuilder sb = new StringBuilder();
		String str;

		for (int i = 1; i <= inputData; i++) {
			if (i % 3 == 0) {
				sb.append(" " + i);
			} else if (i % 10 == 3) {
				sb.append(" " + i);
			} else {
				str = Integer.toString(i);
				char[] ch = str.toCharArray();
				for (int j = 0; j < ch.length; j++) {
					if (ch[j] == '3') {
						sb.append(" " + i);
                                                break;
					}
				}
			}
		}
		System.out.println(sb.toString());
	}
} public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		int inputData = Integer.parseInt(in.readLine());
		StringBuilder sb = new StringBuilder();
		String str;

		for (int i = 1; i <= inputData; i++) {
			if (i % 3 == 0) {
				sb.append(" " + i);
			} else if (i % 10 == 3) {
				sb.append(" " + i);
			} else {
				str = Integer.toString(i);
				char[] ch = str.toCharArray();
				for (int j = 0; j < ch.length; j++) {
					if (ch[j] == '3') {
						sb.append(" " + i);
                                                break;
					}
				}
			}
		}
		System.out.println(sb.toString());
	}
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		int inputData = Integer.parseInt(in.readLine());
		StringBuilder sb = new StringBuilder();
		String str;

		for (int i = 1; i <= inputData; i++) {
			if (i % 3 == 0) {
				sb.append(" " + i);
			} else if (i % 10 == 3) {
				sb.append(" " + i);
			} else {
				str = Integer.toString(i);
				char[] ch = str.toCharArray();
				for (int j = 0; j < ch.length; j++) {
					if (ch[j] == '3') {
						sb.append(" " + i);
                                                break;
					}
				}
			}
		}
		System.out.println(sb.toString());
	}
}