public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		java.util.Scanner sc = new java.util.Scanner(System.in);
		StringBuilder sb = new StringBuilder();

		int n = sc.nextInt();

		loop:
		for (int i = 1; i <= n; i++) {
			int x = i;

			if (x % 3 == 0) {
				sb.append(" " + i);
				continue loop;
			}

			do {
				if (x % 10 == 3) {
					sb.append(" " + i);
					continue loop;
				}
				x /= 10;
			} while (x != 0);
		}

		System.out.println(sb);
	}

} public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		java.util.Scanner sc = new java.util.Scanner(System.in);
		StringBuilder sb = new StringBuilder();

		int n = sc.nextInt();

		loop:
		for (int i = 1; i <= n; i++) {
			int x = i;

			if (x % 3 == 0) {
				sb.append(" " + i);
				continue loop;
			}

			do {
				if (x % 10 == 3) {
					sb.append(" " + i);
					continue loop;
				}
				x /= 10;
			} while (x != 0);
		}

		System.out.println(sb);
	}

} Main public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		java.util.Scanner sc = new java.util.Scanner(System.in);
		StringBuilder sb = new StringBuilder();

		int n = sc.nextInt();

		loop:
		for (int i = 1; i <= n; i++) {
			int x = i;

			if (x % 3 == 0) {
				sb.append(" " + i);
				continue loop;
			}

			do {
				if (x % 10 == 3) {
					sb.append(" " + i);
					continue loop;
				}
				x /= 10;
			} while (x != 0);
		}

		System.out.println(sb);
	} main {
		// TODO ?????????????????????????????????????????????
		java.util.Scanner sc = new java.util.Scanner(System.in);
		StringBuilder sb = new StringBuilder();

		int n = sc.nextInt();

		loop:
		for (int i = 1; i <= n; i++) {
			int x = i;

			if (x % 3 == 0) {
				sb.append(" " + i);
				continue loop;
			}

			do {
				if (x % 10 == 3) {
					sb.append(" " + i);
					continue loop;
				}
				x /= 10;
			} while (x != 0);
		}

		System.out.println(sb);
	} java.util.Scanner sc = new java.util.Scanner(System.in); sc new java.util.Scanner(System.in) StringBuilder sb = new StringBuilder(); sb new StringBuilder() int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc System.out.println(sb) System.out.println System.out System System.out sb String[] args args public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		java.util.Scanner sc = new java.util.Scanner(System.in);
		StringBuilder sb = new StringBuilder();

		int n = sc.nextInt();

		loop:
		for (int i = 1; i <= n; i++) {
			int x = i;

			if (x % 3 == 0) {
				sb.append(" " + i);
				continue loop;
			}

			do {
				if (x % 10 == 3) {
					sb.append(" " + i);
					continue loop;
				}
				x /= 10;
			} while (x != 0);
		}

		System.out.println(sb);
	}

} public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		java.util.Scanner sc = new java.util.Scanner(System.in);
		StringBuilder sb = new StringBuilder();

		int n = sc.nextInt();

		loop:
		for (int i = 1; i <= n; i++) {
			int x = i;

			if (x % 3 == 0) {
				sb.append(" " + i);
				continue loop;
			}

			do {
				if (x % 10 == 3) {
					sb.append(" " + i);
					continue loop;
				}
				x /= 10;
			} while (x != 0);
		}

		System.out.println(sb);
	}

} Main
public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		java.util.Scanner sc = new java.util.Scanner(System.in);
		StringBuilder sb = new StringBuilder();

		int n = sc.nextInt();

		loop:
		for (int i = 1; i <= n; i++) {
			int x = i;

			if (x % 3 == 0) {
				sb.append(" " + i);
				continue loop;
			}

			do {
				if (x % 10 == 3) {
					sb.append(" " + i);
					continue loop;
				}
				x /= 10;
			} while (x != 0);
		}

		System.out.println(sb);
	}

}