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

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();
		int n = Integer.parseInt(br.readLine());

		for (int i = 1; i <= n; i++) {
			if (i % 3 == 0) {
				sb.append(" ").append(i);
				continue;
			}
			int tmp = i;
			do {
				if (i % 10 == 3) {
					i = tmp;
					sb.append(" ").append(i);
					break;
				}
				i /= 10;
			} while (i != 0);
			i = tmp;
		}
		System.out.println(sb);
	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();
		int n = Integer.parseInt(br.readLine());

		for (int i = 1; i <= n; i++) {
			if (i % 3 == 0) {
				sb.append(" ").append(i);
				continue;
			}
			int tmp = i;
			do {
				if (i % 10 == 3) {
					i = tmp;
					sb.append(" ").append(i);
					break;
				}
				i /= 10;
			} while (i != 0);
			i = tmp;
		}
		System.out.println(sb);
	}
} Main public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();
		int n = Integer.parseInt(br.readLine());

		for (int i = 1; i <= n; i++) {
			if (i % 3 == 0) {
				sb.append(" ").append(i);
				continue;
			}
			int tmp = i;
			do {
				if (i % 10 == 3) {
					i = tmp;
					sb.append(" ").append(i);
					break;
				}
				i /= 10;
			} while (i != 0);
			i = tmp;
		}
		System.out.println(sb);
	} main {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();
		int n = Integer.parseInt(br.readLine());

		for (int i = 1; i <= n; i++) {
			if (i % 3 == 0) {
				sb.append(" ").append(i);
				continue;
			}
			int tmp = i;
			do {
				if (i % 10 == 3) {
					i = tmp;
					sb.append(" ").append(i);
					break;
				}
				i /= 10;
			} while (i != 0);
			i = tmp;
		}
		System.out.println(sb);
	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) StringBuilder sb = new StringBuilder(); sb new StringBuilder() int n = Integer.parseInt(br.readLine()); n Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br for (int i = 1; i <= n; i++) {
			if (i % 3 == 0) {
				sb.append(" ").append(i);
				continue;
			}
			int tmp = i;
			do {
				if (i % 10 == 3) {
					i = tmp;
					sb.append(" ").append(i);
					break;
				}
				i /= 10;
			} while (i != 0);
			i = tmp;
		} int i = 1; int i = 1; i 1 i <= n i n i++ i++ i {
			if (i % 3 == 0) {
				sb.append(" ").append(i);
				continue;
			}
			int tmp = i;
			do {
				if (i % 10 == 3) {
					i = tmp;
					sb.append(" ").append(i);
					break;
				}
				i /= 10;
			} while (i != 0);
			i = tmp;
		} {
			if (i % 3 == 0) {
				sb.append(" ").append(i);
				continue;
			}
			int tmp = i;
			do {
				if (i % 10 == 3) {
					i = tmp;
					sb.append(" ").append(i);
					break;
				}
				i /= 10;
			} while (i != 0);
			i = tmp;
		} if (i % 3 == 0) {
				sb.append(" ").append(i);
				continue;
			} i % 3 == 0 i % 3 i 3 0 {
				sb.append(" ").append(i);
				continue;
			} sb.append(" ").append(i) sb.append(" ").append sb.append(" ") sb.append sb " " i continue; int tmp = i; tmp i do {
				if (i % 10 == 3) {
					i = tmp;
					sb.append(" ").append(i);
					break;
				}
				i /= 10;
			} while (i != 0); i != 0 i 0 {
				if (i % 10 == 3) {
					i = tmp;
					sb.append(" ").append(i);
					break;
				}
				i /= 10;
			} if (i % 10 == 3) {
					i = tmp;
					sb.append(" ").append(i);
					break;
				} i % 10 == 3 i % 10 i 10 3 {
					i = tmp;
					sb.append(" ").append(i);
					break;
				} i = tmp i tmp sb.append(" ").append(i) sb.append(" ").append sb.append(" ") sb.append sb " " i break; i /= 10 i 10 i = tmp i tmp 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) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();
		int n = Integer.parseInt(br.readLine());

		for (int i = 1; i <= n; i++) {
			if (i % 3 == 0) {
				sb.append(" ").append(i);
				continue;
			}
			int tmp = i;
			do {
				if (i % 10 == 3) {
					i = tmp;
					sb.append(" ").append(i);
					break;
				}
				i /= 10;
			} while (i != 0);
			i = tmp;
		}
		System.out.println(sb);
	}
} public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();
		int n = Integer.parseInt(br.readLine());

		for (int i = 1; i <= n; i++) {
			if (i % 3 == 0) {
				sb.append(" ").append(i);
				continue;
			}
			int tmp = i;
			do {
				if (i % 10 == 3) {
					i = tmp;
					sb.append(" ").append(i);
					break;
				}
				i /= 10;
			} while (i != 0);
			i = tmp;
		}
		System.out.println(sb);
	}
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();
		int n = Integer.parseInt(br.readLine());

		for (int i = 1; i <= n; i++) {
			if (i % 3 == 0) {
				sb.append(" ").append(i);
				continue;
			}
			int tmp = i;
			do {
				if (i % 10 == 3) {
					i = tmp;
					sb.append(" ").append(i);
					break;
				}
				i /= 10;
			} while (i != 0);
			i = tmp;
		}
		System.out.println(sb);
	}
}