import java.util.Scanner;

class Main {

	public static void main(String[] args) {

		String s;
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();

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

	}

} import java.util.Scanner; Scanner java.util class Main {

	public static void main(String[] args) {

		String s;
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();

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

	}

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

		String s;
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();

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

	} main {

		String s;
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();

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

	} String s; s Scanner stdIn = new Scanner(System.in); stdIn new Scanner(System.in) int n = stdIn.nextInt(); n stdIn.nextInt() stdIn.nextInt stdIn for (int i = 3; i <= n; i++) {
			if ((i % 3) == 0) {
				System.out.print(" " + i);
			} else if ((i % 10) == 10) {
				System.out.print(" " + i);
			} else if (String.valueOf(i).contains("3")) {
				System.out.print(" " + i);
			}
		} int i = 3; int i = 3; i 3 i <= n i n i++ i++ i {
			if ((i % 3) == 0) {
				System.out.print(" " + i);
			} else if ((i % 10) == 10) {
				System.out.print(" " + i);
			} else if (String.valueOf(i).contains("3")) {
				System.out.print(" " + i);
			}
		} {
			if ((i % 3) == 0) {
				System.out.print(" " + i);
			} else if ((i % 10) == 10) {
				System.out.print(" " + i);
			} else if (String.valueOf(i).contains("3")) {
				System.out.print(" " + i);
			}
		} if ((i % 3) == 0) {
				System.out.print(" " + i);
			} else if ((i % 10) == 10) {
				System.out.print(" " + i);
			} else if (String.valueOf(i).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 if ((i % 10) == 10) {
				System.out.print(" " + i);
			} else if (String.valueOf(i).contains("3")) {
				System.out.print(" " + i);
			} (i % 10) == 10 (i % 10) i 10 10 {
				System.out.print(" " + i);
			} System.out.print(" " + i) System.out.print System.out System System.out " " + i " " i if (String.valueOf(i).contains("3")) {
				System.out.print(" " + i);
			} String.valueOf(i).contains("3") String.valueOf(i).contains String.valueOf(i) String.valueOf String i "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
import java.util.Scanner;

class Main {

	public static void main(String[] args) {

		String s;
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();

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

	}

}