import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception {
		BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
		String s;
		int inCnt = 0;
		while ((s = stdIn.readLine()) != null) {
			inCnt++;
			String[] se = s.split(" ");
			int e = Integer.valueOf(se[0]);
			doMain(inCnt, e);
		}
		System.exit(0);
	}

	private static void doMain(int inCnt, int e) {
		for (int i = 1; i <= e; i++) {
			if (i % 3 == 0)
				System.out.print(" " + i);
			else
				for (int j = i; j != 0; j /= 10)
					if (j % 10 == 3) {
						System.out.print(" " + i);
						break;
					}
		}
		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 stdIn = new BufferedReader(new InputStreamReader(System.in));
		String s;
		int inCnt = 0;
		while ((s = stdIn.readLine()) != null) {
			inCnt++;
			String[] se = s.split(" ");
			int e = Integer.valueOf(se[0]);
			doMain(inCnt, e);
		}
		System.exit(0);
	}

	private static void doMain(int inCnt, int e) {
		for (int i = 1; i <= e; i++) {
			if (i % 3 == 0)
				System.out.print(" " + i);
			else
				for (int j = i; j != 0; j /= 10)
					if (j % 10 == 3) {
						System.out.print(" " + i);
						break;
					}
		}
		System.out.println("");

	}
} Main public static void main(String[] args) throws Exception {
		BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
		String s;
		int inCnt = 0;
		while ((s = stdIn.readLine()) != null) {
			inCnt++;
			String[] se = s.split(" ");
			int e = Integer.valueOf(se[0]);
			doMain(inCnt, e);
		}
		System.exit(0);
	} main {
		BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
		String s;
		int inCnt = 0;
		while ((s = stdIn.readLine()) != null) {
			inCnt++;
			String[] se = s.split(" ");
			int e = Integer.valueOf(se[0]);
			doMain(inCnt, e);
		}
		System.exit(0);
	} BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in)); stdIn new BufferedReader(new InputStreamReader(System.in)) String s; s int inCnt = 0; inCnt 0 while ((s = stdIn.readLine()) != null) {
			inCnt++;
			String[] se = s.split(" ");
			int e = Integer.valueOf(se[0]);
			doMain(inCnt, e);
		} (s = stdIn.readLine()) != null (s = stdIn.readLine()) s stdIn.readLine() stdIn.readLine stdIn null {
			inCnt++;
			String[] se = s.split(" ");
			int e = Integer.valueOf(se[0]);
			doMain(inCnt, e);
		} inCnt++ inCnt String[] se = s.split(" "); se s.split(" ") s.split s " " int e = Integer.valueOf(se[0]); e Integer.valueOf(se[0]) Integer.valueOf Integer se[0] se 0 doMain(inCnt, e) doMain inCnt e System.exit(0) System.exit System 0 String[] args args private static void doMain(int inCnt, int e) {
		for (int i = 1; i <= e; i++) {
			if (i % 3 == 0)
				System.out.print(" " + i);
			else
				for (int j = i; j != 0; j /= 10)
					if (j % 10 == 3) {
						System.out.print(" " + i);
						break;
					}
		}
		System.out.println("");

	} doMain {
		for (int i = 1; i <= e; i++) {
			if (i % 3 == 0)
				System.out.print(" " + i);
			else
				for (int j = i; j != 0; j /= 10)
					if (j % 10 == 3) {
						System.out.print(" " + i);
						break;
					}
		}
		System.out.println("");

	} for (int i = 1; i <= e; i++) {
			if (i % 3 == 0)
				System.out.print(" " + i);
			else
				for (int j = i; j != 0; j /= 10)
					if (j % 10 == 3) {
						System.out.print(" " + i);
						break;
					}
		} int i = 1; int i = 1; i 1 i <= e i e i++ i++ i {
			if (i % 3 == 0)
				System.out.print(" " + i);
			else
				for (int j = i; j != 0; j /= 10)
					if (j % 10 == 3) {
						System.out.print(" " + i);
						break;
					}
		} {
			if (i % 3 == 0)
				System.out.print(" " + i);
			else
				for (int j = i; j != 0; j /= 10)
					if (j % 10 == 3) {
						System.out.print(" " + i);
						break;
					}
		} if (i % 3 == 0)
				System.out.print(" " + i);
			else
				for (int j = i; j != 0; j /= 10)
					if (j % 10 == 3) {
						System.out.print(" " + i);
						break;
					} i % 3 == 0 i % 3 i 3 0 System.out.print(" " + i) System.out.print System.out System System.out " " + i " " i for (int j = i; j != 0; j /= 10)
					if (j % 10 == 3) {
						System.out.print(" " + i);
						break;
					} int j = i; int j = i; j i j != 0 j 0 j /= 10 j /= 10 j 10 if (j % 10 == 3) {
						System.out.print(" " + i);
						break;
					} if (j % 10 == 3) {
						System.out.print(" " + i);
						break;
					} j % 10 == 3 j % 10 j 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 "" int inCnt inCnt int e e public class Main {

	public static void main(String[] args) throws Exception {
		BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
		String s;
		int inCnt = 0;
		while ((s = stdIn.readLine()) != null) {
			inCnt++;
			String[] se = s.split(" ");
			int e = Integer.valueOf(se[0]);
			doMain(inCnt, e);
		}
		System.exit(0);
	}

	private static void doMain(int inCnt, int e) {
		for (int i = 1; i <= e; i++) {
			if (i % 3 == 0)
				System.out.print(" " + i);
			else
				for (int j = i; j != 0; j /= 10)
					if (j % 10 == 3) {
						System.out.print(" " + i);
						break;
					}
		}
		System.out.println("");

	}
} public class Main {

	public static void main(String[] args) throws Exception {
		BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
		String s;
		int inCnt = 0;
		while ((s = stdIn.readLine()) != null) {
			inCnt++;
			String[] se = s.split(" ");
			int e = Integer.valueOf(se[0]);
			doMain(inCnt, e);
		}
		System.exit(0);
	}

	private static void doMain(int inCnt, int e) {
		for (int i = 1; i <= e; i++) {
			if (i % 3 == 0)
				System.out.print(" " + i);
			else
				for (int j = i; j != 0; j /= 10)
					if (j % 10 == 3) {
						System.out.print(" " + i);
						break;
					}
		}
		System.out.println("");

	}
} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception {
		BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
		String s;
		int inCnt = 0;
		while ((s = stdIn.readLine()) != null) {
			inCnt++;
			String[] se = s.split(" ");
			int e = Integer.valueOf(se[0]);
			doMain(inCnt, e);
		}
		System.exit(0);
	}

	private static void doMain(int inCnt, int e) {
		for (int i = 1; i <= e; i++) {
			if (i % 3 == 0)
				System.out.print(" " + i);
			else
				for (int j = i; j != 0; j /= 10)
					if (j % 10 == 3) {
						System.out.print(" " + i);
						break;
					}
		}
		System.out.println("");

	}
}