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

class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		Integer num = Integer.parseInt(br.readLine());
		ArrayList<Integer> numArrays = new ArrayList<Integer>();
		for (int i = 1; i <= num; i++) {
			int x = i;
			if (x % 3 == 0) {
				numArrays.add(i);
			} else {
				while (x != 0) {
					if (x % 10 == 3) {
						numArrays.add(i);
						break;
					}
					x /= 10;
				}
			}
		}
		String out = "";
		for (int i = 0; i < numArrays.size(); i++) {
			out += " " + numArrays.get(i);
		}
		System.out.println(out);
	}

} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.ArrayList; ArrayList java.util class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		Integer num = Integer.parseInt(br.readLine());
		ArrayList<Integer> numArrays = new ArrayList<Integer>();
		for (int i = 1; i <= num; i++) {
			int x = i;
			if (x % 3 == 0) {
				numArrays.add(i);
			} else {
				while (x != 0) {
					if (x % 10 == 3) {
						numArrays.add(i);
						break;
					}
					x /= 10;
				}
			}
		}
		String out = "";
		for (int i = 0; i < numArrays.size(); i++) {
			out += " " + numArrays.get(i);
		}
		System.out.println(out);
	}

} Main public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		Integer num = Integer.parseInt(br.readLine());
		ArrayList<Integer> numArrays = new ArrayList<Integer>();
		for (int i = 1; i <= num; i++) {
			int x = i;
			if (x % 3 == 0) {
				numArrays.add(i);
			} else {
				while (x != 0) {
					if (x % 10 == 3) {
						numArrays.add(i);
						break;
					}
					x /= 10;
				}
			}
		}
		String out = "";
		for (int i = 0; i < numArrays.size(); i++) {
			out += " " + numArrays.get(i);
		}
		System.out.println(out);
	} main {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		Integer num = Integer.parseInt(br.readLine());
		ArrayList<Integer> numArrays = new ArrayList<Integer>();
		for (int i = 1; i <= num; i++) {
			int x = i;
			if (x % 3 == 0) {
				numArrays.add(i);
			} else {
				while (x != 0) {
					if (x % 10 == 3) {
						numArrays.add(i);
						break;
					}
					x /= 10;
				}
			}
		}
		String out = "";
		for (int i = 0; i < numArrays.size(); i++) {
			out += " " + numArrays.get(i);
		}
		System.out.println(out);
	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) Integer num = Integer.parseInt(br.readLine()); num Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br ArrayList<Integer> numArrays = new ArrayList<Integer>(); numArrays new ArrayList<Integer>() for (int i = 1; i <= num; i++) {
			int x = i;
			if (x % 3 == 0) {
				numArrays.add(i);
			} else {
				while (x != 0) {
					if (x % 10 == 3) {
						numArrays.add(i);
						break;
					}
					x /= 10;
				}
			}
		} int i = 1; int i = 1; i 1 i <= num i num i++ i++ i {
			int x = i;
			if (x % 3 == 0) {
				numArrays.add(i);
			} else {
				while (x != 0) {
					if (x % 10 == 3) {
						numArrays.add(i);
						break;
					}
					x /= 10;
				}
			}
		} {
			int x = i;
			if (x % 3 == 0) {
				numArrays.add(i);
			} else {
				while (x != 0) {
					if (x % 10 == 3) {
						numArrays.add(i);
						break;
					}
					x /= 10;
				}
			}
		} int x = i; x i if (x % 3 == 0) {
				numArrays.add(i);
			} else {
				while (x != 0) {
					if (x % 10 == 3) {
						numArrays.add(i);
						break;
					}
					x /= 10;
				}
			} x % 3 == 0 x % 3 x 3 0 {
				numArrays.add(i);
			} numArrays.add(i) numArrays.add numArrays i {
				while (x != 0) {
					if (x % 10 == 3) {
						numArrays.add(i);
						break;
					}
					x /= 10;
				}
			} while (x != 0) {
					if (x % 10 == 3) {
						numArrays.add(i);
						break;
					}
					x /= 10;
				} x != 0 x 0 {
					if (x % 10 == 3) {
						numArrays.add(i);
						break;
					}
					x /= 10;
				} if (x % 10 == 3) {
						numArrays.add(i);
						break;
					} x % 10 == 3 x % 10 x 10 3 {
						numArrays.add(i);
						break;
					} numArrays.add(i) numArrays.add numArrays i break; x /= 10 x 10 String out = ""; out "" for (int i = 0; i < numArrays.size(); i++) {
			out += " " + numArrays.get(i);
		} int i = 0; int i = 0; i 0 i < numArrays.size() i numArrays.size() numArrays.size numArrays i++ i++ i {
			out += " " + numArrays.get(i);
		} {
			out += " " + numArrays.get(i);
		} out += " " + numArrays.get(i) out " " + numArrays.get(i) " " numArrays.get(i) numArrays.get numArrays i System.out.println(out) System.out.println System.out System System.out out String[] args args
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		Integer num = Integer.parseInt(br.readLine());
		ArrayList<Integer> numArrays = new ArrayList<Integer>();
		for (int i = 1; i <= num; i++) {
			int x = i;
			if (x % 3 == 0) {
				numArrays.add(i);
			} else {
				while (x != 0) {
					if (x % 10 == 3) {
						numArrays.add(i);
						break;
					}
					x /= 10;
				}
			}
		}
		String out = "";
		for (int i = 0; i < numArrays.size(); i++) {
			out += " " + numArrays.get(i);
		}
		System.out.println(out);
	}

}