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

class Main {

	public static void main(String[] args) {
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(isr);
		try {
			String input = br.readLine();
			int num = Integer.parseInt(input);
			int i, x;
			String ret = "";
			for (i = 2; i <= num; i++) {
				x = i;
				if (x % 3 == 0) {
					ret = ret + " " + i;
				} else {
					ret = INCLUDE3(ret, i, x);
				}
			}
			System.out.println(ret);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	private static String INCLUDE3(String ret, int i, int x) {
		if (x % 10 == 3) {
			ret = ret + " " + i;
		} else {
		x = x / 10;
		if (x > 0) {
			ret = INCLUDE3(ret, i, x);
		}
}
		return ret;
	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io class Main {

	public static void main(String[] args) {
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(isr);
		try {
			String input = br.readLine();
			int num = Integer.parseInt(input);
			int i, x;
			String ret = "";
			for (i = 2; i <= num; i++) {
				x = i;
				if (x % 3 == 0) {
					ret = ret + " " + i;
				} else {
					ret = INCLUDE3(ret, i, x);
				}
			}
			System.out.println(ret);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	private static String INCLUDE3(String ret, int i, int x) {
		if (x % 10 == 3) {
			ret = ret + " " + i;
		} else {
		x = x / 10;
		if (x > 0) {
			ret = INCLUDE3(ret, i, x);
		}
}
		return ret;
	}
} Main public static void main(String[] args) {
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(isr);
		try {
			String input = br.readLine();
			int num = Integer.parseInt(input);
			int i, x;
			String ret = "";
			for (i = 2; i <= num; i++) {
				x = i;
				if (x % 3 == 0) {
					ret = ret + " " + i;
				} else {
					ret = INCLUDE3(ret, i, x);
				}
			}
			System.out.println(ret);
		} catch (IOException e) {
			e.printStackTrace();
		}
	} main {
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(isr);
		try {
			String input = br.readLine();
			int num = Integer.parseInt(input);
			int i, x;
			String ret = "";
			for (i = 2; i <= num; i++) {
				x = i;
				if (x % 3 == 0) {
					ret = ret + " " + i;
				} else {
					ret = INCLUDE3(ret, i, x);
				}
			}
			System.out.println(ret);
		} catch (IOException e) {
			e.printStackTrace();
		}
	} InputStreamReader isr = new InputStreamReader(System.in); isr new InputStreamReader(System.in) BufferedReader br = new BufferedReader(isr); br new BufferedReader(isr) try {
			String input = br.readLine();
			int num = Integer.parseInt(input);
			int i, x;
			String ret = "";
			for (i = 2; i <= num; i++) {
				x = i;
				if (x % 3 == 0) {
					ret = ret + " " + i;
				} else {
					ret = INCLUDE3(ret, i, x);
				}
			}
			System.out.println(ret);
		} catch (IOException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} IOException e {
			e.printStackTrace();
		} e.printStackTrace() e.printStackTrace e {
			String input = br.readLine();
			int num = Integer.parseInt(input);
			int i, x;
			String ret = "";
			for (i = 2; i <= num; i++) {
				x = i;
				if (x % 3 == 0) {
					ret = ret + " " + i;
				} else {
					ret = INCLUDE3(ret, i, x);
				}
			}
			System.out.println(ret);
		} String input = br.readLine(); input br.readLine() br.readLine br int num = Integer.parseInt(input); num Integer.parseInt(input) Integer.parseInt Integer input int i i x; x String ret = ""; ret "" for (i = 2; i <= num; i++) {
				x = i;
				if (x % 3 == 0) {
					ret = ret + " " + i;
				} else {
					ret = INCLUDE3(ret, i, x);
				}
			} i = 2; i = 2 i 2 i <= num i num i++ i++ i {
				x = i;
				if (x % 3 == 0) {
					ret = ret + " " + i;
				} else {
					ret = INCLUDE3(ret, i, x);
				}
			} {
				x = i;
				if (x % 3 == 0) {
					ret = ret + " " + i;
				} else {
					ret = INCLUDE3(ret, i, x);
				}
			} x = i x i if (x % 3 == 0) {
					ret = ret + " " + i;
				} else {
					ret = INCLUDE3(ret, i, x);
				} x % 3 == 0 x % 3 x 3 0 {
					ret = ret + " " + i;
				} ret = ret + " " + i ret ret + " " + i ret + " " + i ret " " i {
					ret = INCLUDE3(ret, i, x);
				} ret = INCLUDE3(ret, i, x) ret INCLUDE3(ret, i, x) INCLUDE3 ret i x System.out.println(ret) System.out.println System.out System System.out ret String[] args args private static String INCLUDE3(String ret, int i, int x) {
		if (x % 10 == 3) {
			ret = ret + " " + i;
		} else {
		x = x / 10;
		if (x > 0) {
			ret = INCLUDE3(ret, i, x);
		}
}
		return ret;
	} INCLUDE3 {
		if (x % 10 == 3) {
			ret = ret + " " + i;
		} else {
		x = x / 10;
		if (x > 0) {
			ret = INCLUDE3(ret, i, x);
		}
}
		return ret;
	} if (x % 10 == 3) {
			ret = ret + " " + i;
		} else {
		x = x / 10;
		if (x > 0) {
			ret = INCLUDE3(ret, i, x);
		}
} x % 10 == 3 x % 10 x 10 3 {
			ret = ret + " " + i;
		} ret = ret + " " + i ret ret + " " + i ret + " " + i ret " " i {
		x = x / 10;
		if (x > 0) {
			ret = INCLUDE3(ret, i, x);
		}
} x = x / 10 x x / 10 x 10 if (x > 0) {
			ret = INCLUDE3(ret, i, x);
		} x > 0 x 0 {
			ret = INCLUDE3(ret, i, x);
		} ret = INCLUDE3(ret, i, x) ret INCLUDE3(ret, i, x) INCLUDE3 ret i x return ret; ret String ret ret int i i int x x
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {

	public static void main(String[] args) {
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(isr);
		try {
			String input = br.readLine();
			int num = Integer.parseInt(input);
			int i, x;
			String ret = "";
			for (i = 2; i <= num; i++) {
				x = i;
				if (x % 3 == 0) {
					ret = ret + " " + i;
				} else {
					ret = INCLUDE3(ret, i, x);
				}
			}
			System.out.println(ret);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	private static String INCLUDE3(String ret, int i, int x) {
		if (x % 10 == 3) {
			ret = ret + " " + i;
		} else {
		x = x / 10;
		if (x > 0) {
			ret = INCLUDE3(ret, i, x);
		}
}
		return ret;
	}
}