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

class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(bf.readLine());
		for (int i = 1; i <= n; i++) {
			if (i % 3 == 0) System.out.print(" " + i);
			else if (i % 10 == 3)  System.out.print(" " + i);
			else {
				int j = i;
				while (j > 0) {
					j /= 10;
					if (j < 3) break;
					else if (j % 10 == 3) {
						System.out.print(" " + i);
						break;
					}
				}
			}
		}
		System.out.println();
	}
} import java.io.InputStreamReader; InputStreamReader java.io import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(bf.readLine());
		for (int i = 1; i <= n; i++) {
			if (i % 3 == 0) System.out.print(" " + i);
			else if (i % 10 == 3)  System.out.print(" " + i);
			else {
				int j = i;
				while (j > 0) {
					j /= 10;
					if (j < 3) break;
					else if (j % 10 == 3) {
						System.out.print(" " + i);
						break;
					}
				}
			}
		}
		System.out.println();
	}
} Main public static void main(String[] args) throws IOException {
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(bf.readLine());
		for (int i = 1; i <= n; i++) {
			if (i % 3 == 0) System.out.print(" " + i);
			else if (i % 10 == 3)  System.out.print(" " + i);
			else {
				int j = i;
				while (j > 0) {
					j /= 10;
					if (j < 3) break;
					else if (j % 10 == 3) {
						System.out.print(" " + i);
						break;
					}
				}
			}
		}
		System.out.println();
	} main {
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(bf.readLine());
		for (int i = 1; i <= n; i++) {
			if (i % 3 == 0) System.out.print(" " + i);
			else if (i % 10 == 3)  System.out.print(" " + i);
			else {
				int j = i;
				while (j > 0) {
					j /= 10;
					if (j < 3) break;
					else if (j % 10 == 3) {
						System.out.print(" " + i);
						break;
					}
				}
			}
		}
		System.out.println();
	} BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); bf new BufferedReader(new InputStreamReader(System.in)) int n = Integer.parseInt(bf.readLine()); n Integer.parseInt(bf.readLine()) Integer.parseInt Integer bf.readLine() bf.readLine bf for (int i = 1; i <= n; i++) {
			if (i % 3 == 0) System.out.print(" " + i);
			else if (i % 10 == 3)  System.out.print(" " + i);
			else {
				int j = i;
				while (j > 0) {
					j /= 10;
					if (j < 3) break;
					else if (j % 10 == 3) {
						System.out.print(" " + i);
						break;
					}
				}
			}
		} int i = 1; int i = 1; i 1 i <= n i n i++ i++ i {
			if (i % 3 == 0) System.out.print(" " + i);
			else if (i % 10 == 3)  System.out.print(" " + i);
			else {
				int j = i;
				while (j > 0) {
					j /= 10;
					if (j < 3) break;
					else if (j % 10 == 3) {
						System.out.print(" " + i);
						break;
					}
				}
			}
		} {
			if (i % 3 == 0) System.out.print(" " + i);
			else if (i % 10 == 3)  System.out.print(" " + i);
			else {
				int j = i;
				while (j > 0) {
					j /= 10;
					if (j < 3) break;
					else if (j % 10 == 3) {
						System.out.print(" " + i);
						break;
					}
				}
			}
		} if (i % 3 == 0) System.out.print(" " + i);
			else if (i % 10 == 3)  System.out.print(" " + i);
			else {
				int j = i;
				while (j > 0) {
					j /= 10;
					if (j < 3) break;
					else if (j % 10 == 3) {
						System.out.print(" " + i);
						break;
					}
				}
			} i % 3 == 0 i % 3 i 3 0 System.out.print(" " + i) System.out.print System.out System System.out " " + i " " i if (i % 10 == 3)  System.out.print(" " + i);
			else {
				int j = i;
				while (j > 0) {
					j /= 10;
					if (j < 3) break;
					else if (j % 10 == 3) {
						System.out.print(" " + i);
						break;
					}
				}
			} i % 10 == 3 i % 10 i 10 3 System.out.print(" " + i) System.out.print System.out System System.out " " + i " " i {
				int j = i;
				while (j > 0) {
					j /= 10;
					if (j < 3) break;
					else if (j % 10 == 3) {
						System.out.print(" " + i);
						break;
					}
				}
			} int j = i; j i while (j > 0) {
					j /= 10;
					if (j < 3) break;
					else if (j % 10 == 3) {
						System.out.print(" " + i);
						break;
					}
				} j > 0 j 0 {
					j /= 10;
					if (j < 3) break;
					else if (j % 10 == 3) {
						System.out.print(" " + i);
						break;
					}
				} j /= 10 j 10 if (j < 3) break;
					else if (j % 10 == 3) {
						System.out.print(" " + i);
						break;
					} j < 3 j 3 break; if (j % 10 == 3) {
						System.out.print(" " + i);
						break;
					} j % 10 == 3 j % 10 j 10 3 {
						System.out.print(" " + i);
						break;
					} System.out.print(" " + i) System.out.print System.out System System.out " " + i " " i break; System.out.println() System.out.println System.out System System.out String[] args args
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.IOException;

class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(bf.readLine());
		for (int i = 1; i <= n; i++) {
			if (i % 3 == 0) System.out.print(" " + i);
			else if (i % 10 == 3)  System.out.print(" " + i);
			else {
				int j = i;
				while (j > 0) {
					j /= 10;
					if (j < 3) break;
					else if (j % 10 == 3) {
						System.out.print(" " + i);
						break;
					}
				}
			}
		}
		System.out.println();
	}
}