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

/**
 * ???????????????
 *
 * @author B7078
 *
 */
class Calcurator {

	public void Cal(int n, String str) { // Cal????????????:3????????°or3???????????´??°????????\

		for (int i = 1; i <= n; ++i) {
			if (i % 3 == 0) { // 3??§?????????????????´??°
				System.out.print(" ");
				System.out.print(i);
			} else if (String.valueOf(i).indexOf("3") != -1) { // ??´??°???"3"????????????????????\
				System.out.print(" ");
				System.out.print(i);
			}
		}
		System.out.println("");
	}
}

public class Main {

	public static void main(String[] args) throws IOException {
		/**
		 *
		 */
		Calcurator cal1;
		cal1 = new Calcurator();
		/**
		 * ?????°?????£?¨?
		 */
		int n = 0;
		String str;
		/**
		 * ??´??°n?????\?????¨??????
		 */
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		str = br.readLine();
		n = Integer.parseInt(str);
		if (n >= 3 || n <= 10000) {
			cal1.Cal(n, str);
		}

	}

} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io class Calcurator {

	public void Cal(int n, String str) { // Cal????????????:3????????°or3???????????´??°????????\

		for (int i = 1; i <= n; ++i) {
			if (i % 3 == 0) { // 3??§?????????????????´??°
				System.out.print(" ");
				System.out.print(i);
			} else if (String.valueOf(i).indexOf("3") != -1) { // ??´??°???"3"????????????????????\
				System.out.print(" ");
				System.out.print(i);
			}
		}
		System.out.println("");
	}
} Calcurator public void Cal(int n, String str) { // Cal????????????:3????????°or3???????????´??°????????\

		for (int i = 1; i <= n; ++i) {
			if (i % 3 == 0) { // 3??§?????????????????´??°
				System.out.print(" ");
				System.out.print(i);
			} else if (String.valueOf(i).indexOf("3") != -1) { // ??´??°???"3"????????????????????\
				System.out.print(" ");
				System.out.print(i);
			}
		}
		System.out.println("");
	} Cal { // Cal????????????:3????????°or3???????????´??°????????\

		for (int i = 1; i <= n; ++i) {
			if (i % 3 == 0) { // 3??§?????????????????´??°
				System.out.print(" ");
				System.out.print(i);
			} else if (String.valueOf(i).indexOf("3") != -1) { // ??´??°???"3"????????????????????\
				System.out.print(" ");
				System.out.print(i);
			}
		}
		System.out.println("");
	} for (int i = 1; i <= n; ++i) {
			if (i % 3 == 0) { // 3??§?????????????????´??°
				System.out.print(" ");
				System.out.print(i);
			} else if (String.valueOf(i).indexOf("3") != -1) { // ??´??°???"3"????????????????????\
				System.out.print(" ");
				System.out.print(i);
			}
		} int i = 1; int i = 1; i 1 i <= n i n ++i ++i i {
			if (i % 3 == 0) { // 3??§?????????????????´??°
				System.out.print(" ");
				System.out.print(i);
			} else if (String.valueOf(i).indexOf("3") != -1) { // ??´??°???"3"????????????????????\
				System.out.print(" ");
				System.out.print(i);
			}
		} {
			if (i % 3 == 0) { // 3??§?????????????????´??°
				System.out.print(" ");
				System.out.print(i);
			} else if (String.valueOf(i).indexOf("3") != -1) { // ??´??°???"3"????????????????????\
				System.out.print(" ");
				System.out.print(i);
			}
		} if (i % 3 == 0) { // 3??§?????????????????´??°
				System.out.print(" ");
				System.out.print(i);
			} else if (String.valueOf(i).indexOf("3") != -1) { // ??´??°???"3"????????????????????\
				System.out.print(" ");
				System.out.print(i);
			} i % 3 == 0 i % 3 i 3 0 { // 3??§?????????????????´??°
				System.out.print(" ");
				System.out.print(i);
			} System.out.print(" ") System.out.print System.out System System.out " " System.out.print(i) System.out.print System.out System System.out i if (String.valueOf(i).indexOf("3") != -1) { // ??´??°???"3"????????????????????\
				System.out.print(" ");
				System.out.print(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 { // ??´??°???"3"????????????????????\
				System.out.print(" ");
				System.out.print(i);
			} System.out.print(" ") System.out.print System.out System System.out " " System.out.print(i) System.out.print System.out System System.out i System.out.println("") System.out.println System.out System System.out "" int n n String str str public class Main {

	public static void main(String[] args) throws IOException {
		/**
		 *
		 */
		Calcurator cal1;
		cal1 = new Calcurator();
		/**
		 * ?????°?????£?¨?
		 */
		int n = 0;
		String str;
		/**
		 * ??´??°n?????\?????¨??????
		 */
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		str = br.readLine();
		n = Integer.parseInt(str);
		if (n >= 3 || n <= 10000) {
			cal1.Cal(n, str);
		}

	}

} Main public static void main(String[] args) throws IOException {
		/**
		 *
		 */
		Calcurator cal1;
		cal1 = new Calcurator();
		/**
		 * ?????°?????£?¨?
		 */
		int n = 0;
		String str;
		/**
		 * ??´??°n?????\?????¨??????
		 */
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		str = br.readLine();
		n = Integer.parseInt(str);
		if (n >= 3 || n <= 10000) {
			cal1.Cal(n, str);
		}

	} main {
		/**
		 *
		 */
		Calcurator cal1;
		cal1 = new Calcurator();
		/**
		 * ?????°?????£?¨?
		 */
		int n = 0;
		String str;
		/**
		 * ??´??°n?????\?????¨??????
		 */
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		str = br.readLine();
		n = Integer.parseInt(str);
		if (n >= 3 || n <= 10000) {
			cal1.Cal(n, str);
		}

	} Calcurator cal1; cal1 cal1 = new Calcurator() cal1 new Calcurator() int n = 0; n 0 String str; str BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) str = br.readLine() str br.readLine() br.readLine br n = Integer.parseInt(str) n Integer.parseInt(str) Integer.parseInt Integer str if (n >= 3 || n <= 10000) {
			cal1.Cal(n, str);
		} n >= 3 || n <= 10000 n >= 3 n 3 n <= 10000 n 10000 {
			cal1.Cal(n, str);
		} cal1.Cal(n, str) cal1.Cal cal1 n str String[] args args public class Main {

	public static void main(String[] args) throws IOException {
		/**
		 *
		 */
		Calcurator cal1;
		cal1 = new Calcurator();
		/**
		 * ?????°?????£?¨?
		 */
		int n = 0;
		String str;
		/**
		 * ??´??°n?????\?????¨??????
		 */
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		str = br.readLine();
		n = Integer.parseInt(str);
		if (n >= 3 || n <= 10000) {
			cal1.Cal(n, str);
		}

	}

} public class Main {

	public static void main(String[] args) throws IOException {
		/**
		 *
		 */
		Calcurator cal1;
		cal1 = new Calcurator();
		/**
		 * ?????°?????£?¨?
		 */
		int n = 0;
		String str;
		/**
		 * ??´??°n?????\?????¨??????
		 */
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		str = br.readLine();
		n = Integer.parseInt(str);
		if (n >= 3 || n <= 10000) {
			cal1.Cal(n, str);
		}

	}

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

/**
 * ???????????????
 *
 * @author B7078
 *
 */
class Calcurator {

	public void Cal(int n, String str) { // Cal????????????:3????????°or3???????????´??°????????\

		for (int i = 1; i <= n; ++i) {
			if (i % 3 == 0) { // 3??§?????????????????´??°
				System.out.print(" ");
				System.out.print(i);
			} else if (String.valueOf(i).indexOf("3") != -1) { // ??´??°???"3"????????????????????\
				System.out.print(" ");
				System.out.print(i);
			}
		}
		System.out.println("");
	}
}

public class Main {

	public static void main(String[] args) throws IOException {
		/**
		 *
		 */
		Calcurator cal1;
		cal1 = new Calcurator();
		/**
		 * ?????°?????£?¨?
		 */
		int n = 0;
		String str;
		/**
		 * ??´??°n?????\?????¨??????
		 */
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		str = br.readLine();
		n = Integer.parseInt(str);
		if (n >= 3 || n <= 10000) {
			cal1.Cal(n, str);
		}

	}

}