import java.util.Scanner;

class Main {
	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int x = scan.nextInt();

		for (int i = 3; i <= x; i++) {
			if (i % 10 == 3 || i % 3 == 0) {
				System.out.print(" " + i);
			}

			else {
				int y = 0;
				y = i;
				while (y > 0) {
					y /= 10;

					if (y % 10 == 3) {
						System.out.print(" " + i);
						break;
					}
				}
			}
		}
		System.out.println();
	}
} import java.util.Scanner; Scanner java.util class Main {
	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int x = scan.nextInt();

		for (int i = 3; i <= x; i++) {
			if (i % 10 == 3 || i % 3 == 0) {
				System.out.print(" " + i);
			}

			else {
				int y = 0;
				y = i;
				while (y > 0) {
					y /= 10;

					if (y % 10 == 3) {
						System.out.print(" " + i);
						break;
					}
				}
			}
		}
		System.out.println();
	}
} Main public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int x = scan.nextInt();

		for (int i = 3; i <= x; i++) {
			if (i % 10 == 3 || i % 3 == 0) {
				System.out.print(" " + i);
			}

			else {
				int y = 0;
				y = i;
				while (y > 0) {
					y /= 10;

					if (y % 10 == 3) {
						System.out.print(" " + i);
						break;
					}
				}
			}
		}
		System.out.println();
	} main {

		Scanner scan = new Scanner(System.in);

		int x = scan.nextInt();

		for (int i = 3; i <= x; i++) {
			if (i % 10 == 3 || i % 3 == 0) {
				System.out.print(" " + i);
			}

			else {
				int y = 0;
				y = i;
				while (y > 0) {
					y /= 10;

					if (y % 10 == 3) {
						System.out.print(" " + i);
						break;
					}
				}
			}
		}
		System.out.println();
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int x = scan.nextInt(); x scan.nextInt() scan.nextInt scan for (int i = 3; i <= x; i++) {
			if (i % 10 == 3 || i % 3 == 0) {
				System.out.print(" " + i);
			}

			else {
				int y = 0;
				y = i;
				while (y > 0) {
					y /= 10;

					if (y % 10 == 3) {
						System.out.print(" " + i);
						break;
					}
				}
			}
		} int i = 3; int i = 3; i 3 i <= x i x i++ i++ i {
			if (i % 10 == 3 || i % 3 == 0) {
				System.out.print(" " + i);
			}

			else {
				int y = 0;
				y = i;
				while (y > 0) {
					y /= 10;

					if (y % 10 == 3) {
						System.out.print(" " + i);
						break;
					}
				}
			}
		} {
			if (i % 10 == 3 || i % 3 == 0) {
				System.out.print(" " + i);
			}

			else {
				int y = 0;
				y = i;
				while (y > 0) {
					y /= 10;

					if (y % 10 == 3) {
						System.out.print(" " + i);
						break;
					}
				}
			}
		} if (i % 10 == 3 || i % 3 == 0) {
				System.out.print(" " + i);
			}

			else {
				int y = 0;
				y = i;
				while (y > 0) {
					y /= 10;

					if (y % 10 == 3) {
						System.out.print(" " + i);
						break;
					}
				}
			} i % 10 == 3 || i % 3 == 0 i % 10 == 3 i % 10 i 10 3 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 {
				int y = 0;
				y = i;
				while (y > 0) {
					y /= 10;

					if (y % 10 == 3) {
						System.out.print(" " + i);
						break;
					}
				}
			} int y = 0; y 0 y = i y i while (y > 0) {
					y /= 10;

					if (y % 10 == 3) {
						System.out.print(" " + i);
						break;
					}
				} y > 0 y 0 {
					y /= 10;

					if (y % 10 == 3) {
						System.out.print(" " + i);
						break;
					}
				} y /= 10 y 10 if (y % 10 == 3) {
						System.out.print(" " + i);
						break;
					} y % 10 == 3 y % 10 y 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.util.Scanner;

class Main {
	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int x = scan.nextInt();

		for (int i = 3; i <= x; i++) {
			if (i % 10 == 3 || i % 3 == 0) {
				System.out.print(" " + i);
			}

			else {
				int y = 0;
				y = i;
				while (y > 0) {
					y /= 10;

					if (y % 10 == 3) {
						System.out.print(" " + i);
						break;
					}
				}
			}
		}
		System.out.println();
	}
}