import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????

		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		int n = Integer.parseInt(line);

		StringBuilder nabeatsu = new StringBuilder(" ");

		for (int i = 1; i <= n; i++) {
			if (i % 3 == 0 || String.valueOf(i).contains("3")) {
				nabeatsu.append(i);
				nabeatsu.append(" ");
			}
		}

		String s = nabeatsu.toString();
		System.out.println(s.substring(0, s.length() - 1));
	}

} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????

		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		int n = Integer.parseInt(line);

		StringBuilder nabeatsu = new StringBuilder(" ");

		for (int i = 1; i <= n; i++) {
			if (i % 3 == 0 || String.valueOf(i).contains("3")) {
				nabeatsu.append(i);
				nabeatsu.append(" ");
			}
		}

		String s = nabeatsu.toString();
		System.out.println(s.substring(0, s.length() - 1));
	}

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

		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		int n = Integer.parseInt(line);

		StringBuilder nabeatsu = new StringBuilder(" ");

		for (int i = 1; i <= n; i++) {
			if (i % 3 == 0 || String.valueOf(i).contains("3")) {
				nabeatsu.append(i);
				nabeatsu.append(" ");
			}
		}

		String s = nabeatsu.toString();
		System.out.println(s.substring(0, s.length() - 1));
	} main {
		// TODO ?????????????????????????????????????????????

		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		int n = Integer.parseInt(line);

		StringBuilder nabeatsu = new StringBuilder(" ");

		for (int i = 1; i <= n; i++) {
			if (i % 3 == 0 || String.valueOf(i).contains("3")) {
				nabeatsu.append(i);
				nabeatsu.append(" ");
			}
		}

		String s = nabeatsu.toString();
		System.out.println(s.substring(0, s.length() - 1));
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String line = sc.nextLine(); line sc.nextLine() sc.nextLine sc int n = Integer.parseInt(line); n Integer.parseInt(line) Integer.parseInt Integer line StringBuilder nabeatsu = new StringBuilder(" "); nabeatsu new StringBuilder(" ") for (int i = 1; i <= n; i++) {
			if (i % 3 == 0 || String.valueOf(i).contains("3")) {
				nabeatsu.append(i);
				nabeatsu.append(" ");
			}
		} int i = 1; int i = 1; i 1 i <= n i n i++ i++ i {
			if (i % 3 == 0 || String.valueOf(i).contains("3")) {
				nabeatsu.append(i);
				nabeatsu.append(" ");
			}
		} {
			if (i % 3 == 0 || String.valueOf(i).contains("3")) {
				nabeatsu.append(i);
				nabeatsu.append(" ");
			}
		} if (i % 3 == 0 || String.valueOf(i).contains("3")) {
				nabeatsu.append(i);
				nabeatsu.append(" ");
			} i % 3 == 0 || String.valueOf(i).contains("3") i % 3 == 0 i % 3 i 3 0 String.valueOf(i).contains("3") String.valueOf(i).contains String.valueOf(i) String.valueOf String i "3" {
				nabeatsu.append(i);
				nabeatsu.append(" ");
			} nabeatsu.append(i) nabeatsu.append nabeatsu i nabeatsu.append(" ") nabeatsu.append nabeatsu " " String s = nabeatsu.toString(); s nabeatsu.toString() nabeatsu.toString nabeatsu System.out.println(s.substring(0, s.length() - 1)) System.out.println System.out System System.out s.substring(0, s.length() - 1) s.substring s 0 s.length() - 1 s.length() s.length s 1 String[] args args public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????

		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		int n = Integer.parseInt(line);

		StringBuilder nabeatsu = new StringBuilder(" ");

		for (int i = 1; i <= n; i++) {
			if (i % 3 == 0 || String.valueOf(i).contains("3")) {
				nabeatsu.append(i);
				nabeatsu.append(" ");
			}
		}

		String s = nabeatsu.toString();
		System.out.println(s.substring(0, s.length() - 1));
	}

} public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????

		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		int n = Integer.parseInt(line);

		StringBuilder nabeatsu = new StringBuilder(" ");

		for (int i = 1; i <= n; i++) {
			if (i % 3 == 0 || String.valueOf(i).contains("3")) {
				nabeatsu.append(i);
				nabeatsu.append(" ");
			}
		}

		String s = nabeatsu.toString();
		System.out.println(s.substring(0, s.length() - 1));
	}

} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????

		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		int n = Integer.parseInt(line);

		StringBuilder nabeatsu = new StringBuilder(" ");

		for (int i = 1; i <= n; i++) {
			if (i % 3 == 0 || String.valueOf(i).contains("3")) {
				nabeatsu.append(i);
				nabeatsu.append(" ");
			}
		}

		String s = nabeatsu.toString();
		System.out.println(s.substring(0, s.length() - 1));
	}

}