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);

		for (int i = 1; i <= n; i++) {
			if (i % 3 == 0) {
				System.out.print(" " + i);
			} else {
				String s = Integer.toString(i);
				if (s.contains("3")) {
					System.out.print(" " + i);
				}
			}
		}
		System.out.println("");
	}
} 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);

		for (int i = 1; i <= n; i++) {
			if (i % 3 == 0) {
				System.out.print(" " + i);
			} else {
				String s = Integer.toString(i);
				if (s.contains("3")) {
					System.out.print(" " + i);
				}
			}
		}
		System.out.println("");
	}
} 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);

		for (int i = 1; i <= n; i++) {
			if (i % 3 == 0) {
				System.out.print(" " + i);
			} else {
				String s = Integer.toString(i);
				if (s.contains("3")) {
					System.out.print(" " + i);
				}
			}
		}
		System.out.println("");
	} main {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String line = br.readLine();
		int n  = Integer.parseInt(line);

		for (int i = 1; i <= n; i++) {
			if (i % 3 == 0) {
				System.out.print(" " + i);
			} else {
				String s = Integer.toString(i);
				if (s.contains("3")) {
					System.out.print(" " + i);
				}
			}
		}
		System.out.println("");
	} 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 for (int i = 1; i <= n; i++) {
			if (i % 3 == 0) {
				System.out.print(" " + i);
			} else {
				String s = Integer.toString(i);
				if (s.contains("3")) {
					System.out.print(" " + i);
				}
			}
		} int i = 1; int i = 1; i 1 i <= n i n i++ i++ i {
			if (i % 3 == 0) {
				System.out.print(" " + i);
			} else {
				String s = Integer.toString(i);
				if (s.contains("3")) {
					System.out.print(" " + i);
				}
			}
		} {
			if (i % 3 == 0) {
				System.out.print(" " + i);
			} else {
				String s = Integer.toString(i);
				if (s.contains("3")) {
					System.out.print(" " + i);
				}
			}
		} if (i % 3 == 0) {
				System.out.print(" " + i);
			} else {
				String s = Integer.toString(i);
				if (s.contains("3")) {
					System.out.print(" " + i);
				}
			} i % 3 == 0 i % 3 i 3 0 {
				System.out.print(" " + i);
			} System.out.print(" " + i) System.out.print System.out System System.out " " + i " " i {
				String s = Integer.toString(i);
				if (s.contains("3")) {
					System.out.print(" " + i);
				}
			} String s = Integer.toString(i); s Integer.toString(i) Integer.toString Integer i if (s.contains("3")) {
					System.out.print(" " + i);
				} s.contains("3") s.contains s "3" {
					System.out.print(" " + i);
				} System.out.print(" " + i) System.out.print System.out System System.out " " + i " " i System.out.println("") System.out.println System.out System System.out "" 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);

		for (int i = 1; i <= n; i++) {
			if (i % 3 == 0) {
				System.out.print(" " + i);
			} else {
				String s = Integer.toString(i);
				if (s.contains("3")) {
					System.out.print(" " + i);
				}
			}
		}
		System.out.println("");
	}
} 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);

		for (int i = 1; i <= n; i++) {
			if (i % 3 == 0) {
				System.out.print(" " + i);
			} else {
				String s = Integer.toString(i);
				if (s.contains("3")) {
					System.out.print(" " + i);
				}
			}
		}
		System.out.println("");
	}
} 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);

		for (int i = 1; i <= n; i++) {
			if (i % 3 == 0) {
				System.out.print(" " + i);
			} else {
				String s = Integer.toString(i);
				if (s.contains("3")) {
					System.out.print(" " + i);
				}
			}
		}
		System.out.println("");
	}
}