

import java.util.*;

public class Main {
	public static void main(String args[]) {
		Scanner scan = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int n, x;
		n = scan.nextInt();

		for (int count = 1; count <= n; count++) {
			if ((count % 3 == 0)) {
				sb.append(" ");
				sb.append(count);
			} else {

				x = count;

				do {// ?????°??????????????????3?????????????????°??????????????????
					if (x % 10 == 3) {//3???????????????????¢???????????????¶
						sb.append(" ");
						sb.append(count);
						break;
					}
					x = x / 10;//?????????????????¨???
				} while (x != 0);

			}
		}

		System.out.println(new String(sb));

	}
} import java.util.*; util.* java public class Main {
	public static void main(String args[]) {
		Scanner scan = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int n, x;
		n = scan.nextInt();

		for (int count = 1; count <= n; count++) {
			if ((count % 3 == 0)) {
				sb.append(" ");
				sb.append(count);
			} else {

				x = count;

				do {// ?????°??????????????????3?????????????????°??????????????????
					if (x % 10 == 3) {//3???????????????????¢???????????????¶
						sb.append(" ");
						sb.append(count);
						break;
					}
					x = x / 10;//?????????????????¨???
				} while (x != 0);

			}
		}

		System.out.println(new String(sb));

	}
} Main public static void main(String args[]) {
		Scanner scan = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int n, x;
		n = scan.nextInt();

		for (int count = 1; count <= n; count++) {
			if ((count % 3 == 0)) {
				sb.append(" ");
				sb.append(count);
			} else {

				x = count;

				do {// ?????°??????????????????3?????????????????°??????????????????
					if (x % 10 == 3) {//3???????????????????¢???????????????¶
						sb.append(" ");
						sb.append(count);
						break;
					}
					x = x / 10;//?????????????????¨???
				} while (x != 0);

			}
		}

		System.out.println(new String(sb));

	} main {
		Scanner scan = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int n, x;
		n = scan.nextInt();

		for (int count = 1; count <= n; count++) {
			if ((count % 3 == 0)) {
				sb.append(" ");
				sb.append(count);
			} else {

				x = count;

				do {// ?????°??????????????????3?????????????????°??????????????????
					if (x % 10 == 3) {//3???????????????????¢???????????????¶
						sb.append(" ");
						sb.append(count);
						break;
					}
					x = x / 10;//?????????????????¨???
				} while (x != 0);

			}
		}

		System.out.println(new String(sb));

	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) StringBuilder sb = new StringBuilder(); sb new StringBuilder() int n n x; x n = scan.nextInt() n scan.nextInt() scan.nextInt scan for (int count = 1; count <= n; count++) {
			if ((count % 3 == 0)) {
				sb.append(" ");
				sb.append(count);
			} else {

				x = count;

				do {// ?????°??????????????????3?????????????????°??????????????????
					if (x % 10 == 3) {//3???????????????????¢???????????????¶
						sb.append(" ");
						sb.append(count);
						break;
					}
					x = x / 10;//?????????????????¨???
				} while (x != 0);

			}
		} int count = 1; int count = 1; count 1 count <= n count n count++ count++ count {
			if ((count % 3 == 0)) {
				sb.append(" ");
				sb.append(count);
			} else {

				x = count;

				do {// ?????°??????????????????3?????????????????°??????????????????
					if (x % 10 == 3) {//3???????????????????¢???????????????¶
						sb.append(" ");
						sb.append(count);
						break;
					}
					x = x / 10;//?????????????????¨???
				} while (x != 0);

			}
		} {
			if ((count % 3 == 0)) {
				sb.append(" ");
				sb.append(count);
			} else {

				x = count;

				do {// ?????°??????????????????3?????????????????°??????????????????
					if (x % 10 == 3) {//3???????????????????¢???????????????¶
						sb.append(" ");
						sb.append(count);
						break;
					}
					x = x / 10;//?????????????????¨???
				} while (x != 0);

			}
		} if ((count % 3 == 0)) {
				sb.append(" ");
				sb.append(count);
			} else {

				x = count;

				do {// ?????°??????????????????3?????????????????°??????????????????
					if (x % 10 == 3) {//3???????????????????¢???????????????¶
						sb.append(" ");
						sb.append(count);
						break;
					}
					x = x / 10;//?????????????????¨???
				} while (x != 0);

			} (count % 3 == 0) count % 3 count 3 0 {
				sb.append(" ");
				sb.append(count);
			} sb.append(" ") sb.append sb " " sb.append(count) sb.append sb count {

				x = count;

				do {// ?????°??????????????????3?????????????????°??????????????????
					if (x % 10 == 3) {//3???????????????????¢???????????????¶
						sb.append(" ");
						sb.append(count);
						break;
					}
					x = x / 10;//?????????????????¨???
				} while (x != 0);

			} x = count x count do {// ?????°??????????????????3?????????????????°??????????????????
					if (x % 10 == 3) {//3???????????????????¢???????????????¶
						sb.append(" ");
						sb.append(count);
						break;
					}
					x = x / 10;//?????????????????¨???
				} while (x != 0); x != 0 x 0 {// ?????°??????????????????3?????????????????°??????????????????
					if (x % 10 == 3) {//3???????????????????¢???????????????¶
						sb.append(" ");
						sb.append(count);
						break;
					}
					x = x / 10;//?????????????????¨???
				} if (x % 10 == 3) {//3???????????????????¢???????????????¶
						sb.append(" ");
						sb.append(count);
						break;
					} x % 10 == 3 x % 10 x 10 3 {//3???????????????????¢???????????????¶
						sb.append(" ");
						sb.append(count);
						break;
					} sb.append(" ") sb.append sb " " sb.append(count) sb.append sb count break; x = x / 10 x x / 10 x 10 System.out.println(new String(sb)) System.out.println System.out System System.out new String(sb) String args[] args public class Main {
	public static void main(String args[]) {
		Scanner scan = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int n, x;
		n = scan.nextInt();

		for (int count = 1; count <= n; count++) {
			if ((count % 3 == 0)) {
				sb.append(" ");
				sb.append(count);
			} else {

				x = count;

				do {// ?????°??????????????????3?????????????????°??????????????????
					if (x % 10 == 3) {//3???????????????????¢???????????????¶
						sb.append(" ");
						sb.append(count);
						break;
					}
					x = x / 10;//?????????????????¨???
				} while (x != 0);

			}
		}

		System.out.println(new String(sb));

	}
} public class Main {
	public static void main(String args[]) {
		Scanner scan = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int n, x;
		n = scan.nextInt();

		for (int count = 1; count <= n; count++) {
			if ((count % 3 == 0)) {
				sb.append(" ");
				sb.append(count);
			} else {

				x = count;

				do {// ?????°??????????????????3?????????????????°??????????????????
					if (x % 10 == 3) {//3???????????????????¢???????????????¶
						sb.append(" ");
						sb.append(count);
						break;
					}
					x = x / 10;//?????????????????¨???
				} while (x != 0);

			}
		}

		System.out.println(new String(sb));

	}
} Main


import java.util.*;

public class Main {
	public static void main(String args[]) {
		Scanner scan = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int n, x;
		n = scan.nextInt();

		for (int count = 1; count <= n; count++) {
			if ((count % 3 == 0)) {
				sb.append(" ");
				sb.append(count);
			} else {

				x = count;

				do {// ?????°??????????????????3?????????????????°??????????????????
					if (x % 10 == 3) {//3???????????????????¢???????????????¶
						sb.append(" ");
						sb.append(count);
						break;
					}
					x = x / 10;//?????????????????¨???
				} while (x != 0);

			}
		}

		System.out.println(new String(sb));

	}
}