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

public class Main {

	public static void main(String[] args) {

		//?????£?????????
		int numN;

		try {
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

			String line = br.readLine();

			numN = Integer.parseInt(line);

			//????????¨
			String outputNum = "";

			for (int i = 1; i <= numN; i++) {



				//3????????°????????§??????
				if(i % 3 == 0){
					outputNum +=" " + i;

				//3???????????°???????????§??????
				}else if (String.valueOf(i).indexOf("3") != -1) {
					outputNum +=" " + i;
				}
			}
			//???????????????
			System.out.println(outputNum);
		}catch (NumberFormatException e) {
			System.out.println(e);
		} catch (IOException e) {
			System.out.println(e);
		}

	}

} 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) {

		//?????£?????????
		int numN;

		try {
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

			String line = br.readLine();

			numN = Integer.parseInt(line);

			//????????¨
			String outputNum = "";

			for (int i = 1; i <= numN; i++) {



				//3????????°????????§??????
				if(i % 3 == 0){
					outputNum +=" " + i;

				//3???????????°???????????§??????
				}else if (String.valueOf(i).indexOf("3") != -1) {
					outputNum +=" " + i;
				}
			}
			//???????????????
			System.out.println(outputNum);
		}catch (NumberFormatException e) {
			System.out.println(e);
		} catch (IOException e) {
			System.out.println(e);
		}

	}

} Main public static void main(String[] args) {

		//?????£?????????
		int numN;

		try {
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

			String line = br.readLine();

			numN = Integer.parseInt(line);

			//????????¨
			String outputNum = "";

			for (int i = 1; i <= numN; i++) {



				//3????????°????????§??????
				if(i % 3 == 0){
					outputNum +=" " + i;

				//3???????????°???????????§??????
				}else if (String.valueOf(i).indexOf("3") != -1) {
					outputNum +=" " + i;
				}
			}
			//???????????????
			System.out.println(outputNum);
		}catch (NumberFormatException e) {
			System.out.println(e);
		} catch (IOException e) {
			System.out.println(e);
		}

	} main {

		//?????£?????????
		int numN;

		try {
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

			String line = br.readLine();

			numN = Integer.parseInt(line);

			//????????¨
			String outputNum = "";

			for (int i = 1; i <= numN; i++) {



				//3????????°????????§??????
				if(i % 3 == 0){
					outputNum +=" " + i;

				//3???????????°???????????§??????
				}else if (String.valueOf(i).indexOf("3") != -1) {
					outputNum +=" " + i;
				}
			}
			//???????????????
			System.out.println(outputNum);
		}catch (NumberFormatException e) {
			System.out.println(e);
		} catch (IOException e) {
			System.out.println(e);
		}

	} int numN; numN try {
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

			String line = br.readLine();

			numN = Integer.parseInt(line);

			//????????¨
			String outputNum = "";

			for (int i = 1; i <= numN; i++) {



				//3????????°????????§??????
				if(i % 3 == 0){
					outputNum +=" " + i;

				//3???????????°???????????§??????
				}else if (String.valueOf(i).indexOf("3") != -1) {
					outputNum +=" " + i;
				}
			}
			//???????????????
			System.out.println(outputNum);
		}catch (NumberFormatException e) {
			System.out.println(e);
		} catch (IOException e) {
			System.out.println(e);
		} catch (NumberFormatException e) {
			System.out.println(e);
		} NumberFormatException e {
			System.out.println(e);
		} System.out.println(e) System.out.println System.out System System.out e catch (IOException e) {
			System.out.println(e);
		} IOException e {
			System.out.println(e);
		} System.out.println(e) System.out.println System.out System System.out e {
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

			String line = br.readLine();

			numN = Integer.parseInt(line);

			//????????¨
			String outputNum = "";

			for (int i = 1; i <= numN; i++) {



				//3????????°????????§??????
				if(i % 3 == 0){
					outputNum +=" " + i;

				//3???????????°???????????§??????
				}else if (String.valueOf(i).indexOf("3") != -1) {
					outputNum +=" " + i;
				}
			}
			//???????????????
			System.out.println(outputNum);
		} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String line = br.readLine(); line br.readLine() br.readLine br numN = Integer.parseInt(line) numN Integer.parseInt(line) Integer.parseInt Integer line String outputNum = ""; outputNum "" for (int i = 1; i <= numN; i++) {



				//3????????°????????§??????
				if(i % 3 == 0){
					outputNum +=" " + i;

				//3???????????°???????????§??????
				}else if (String.valueOf(i).indexOf("3") != -1) {
					outputNum +=" " + i;
				}
			} int i = 1; int i = 1; i 1 i <= numN i numN i++ i++ i {



				//3????????°????????§??????
				if(i % 3 == 0){
					outputNum +=" " + i;

				//3???????????°???????????§??????
				}else if (String.valueOf(i).indexOf("3") != -1) {
					outputNum +=" " + i;
				}
			} {



				//3????????°????????§??????
				if(i % 3 == 0){
					outputNum +=" " + i;

				//3???????????°???????????§??????
				}else if (String.valueOf(i).indexOf("3") != -1) {
					outputNum +=" " + i;
				}
			} if(i % 3 == 0){
					outputNum +=" " + i;

				//3???????????°???????????§??????
				}else if (String.valueOf(i).indexOf("3") != -1) {
					outputNum +=" " + i;
				} i % 3 == 0 i % 3 i 3 0 {
					outputNum +=" " + i;

				//3???????????°???????????§??????
				} outputNum +=" " + i outputNum " " + i " " i if (String.valueOf(i).indexOf("3") != -1) {
					outputNum +=" " + i;
				} String.valueOf(i).indexOf("3") != -1 String.valueOf(i).indexOf("3") String.valueOf(i).indexOf String.valueOf(i) String.valueOf String i "3" -1 1 {
					outputNum +=" " + i;
				} outputNum +=" " + i outputNum " " + i " " i System.out.println(outputNum) System.out.println System.out System System.out outputNum String[] args args public class Main {

	public static void main(String[] args) {

		//?????£?????????
		int numN;

		try {
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

			String line = br.readLine();

			numN = Integer.parseInt(line);

			//????????¨
			String outputNum = "";

			for (int i = 1; i <= numN; i++) {



				//3????????°????????§??????
				if(i % 3 == 0){
					outputNum +=" " + i;

				//3???????????°???????????§??????
				}else if (String.valueOf(i).indexOf("3") != -1) {
					outputNum +=" " + i;
				}
			}
			//???????????????
			System.out.println(outputNum);
		}catch (NumberFormatException e) {
			System.out.println(e);
		} catch (IOException e) {
			System.out.println(e);
		}

	}

} public class Main {

	public static void main(String[] args) {

		//?????£?????????
		int numN;

		try {
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

			String line = br.readLine();

			numN = Integer.parseInt(line);

			//????????¨
			String outputNum = "";

			for (int i = 1; i <= numN; i++) {



				//3????????°????????§??????
				if(i % 3 == 0){
					outputNum +=" " + i;

				//3???????????°???????????§??????
				}else if (String.valueOf(i).indexOf("3") != -1) {
					outputNum +=" " + i;
				}
			}
			//???????????????
			System.out.println(outputNum);
		}catch (NumberFormatException e) {
			System.out.println(e);
		} catch (IOException e) {
			System.out.println(e);
		}

	}

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

public class Main {

	public static void main(String[] args) {

		//?????£?????????
		int numN;

		try {
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

			String line = br.readLine();

			numN = Integer.parseInt(line);

			//????????¨
			String outputNum = "";

			for (int i = 1; i <= numN; i++) {



				//3????????°????????§??????
				if(i % 3 == 0){
					outputNum +=" " + i;

				//3???????????°???????????§??????
				}else if (String.valueOf(i).indexOf("3") != -1) {
					outputNum +=" " + i;
				}
			}
			//???????????????
			System.out.println(outputNum);
		}catch (NumberFormatException e) {
			System.out.println(e);
		} catch (IOException e) {
			System.out.println(e);
		}

	}

}