import java.util.Scanner;

public class Main {
	public static void main(String[] arges) {

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

		for (int i = 1; i <= v; i++) {
			if (i % 3 == 0) {
				System.out.print(" " + i);
			}
			else if (String.valueOf(i).contains("3")) {
				System.out.print(" " + i);
			}
		}
		System.out.println("");
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] arges) {

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

		for (int i = 1; i <= v; i++) {
			if (i % 3 == 0) {
				System.out.print(" " + i);
			}
			else if (String.valueOf(i).contains("3")) {
				System.out.print(" " + i);
			}
		}
		System.out.println("");
	}
} Main public static void main(String[] arges) {

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

		for (int i = 1; i <= v; i++) {
			if (i % 3 == 0) {
				System.out.print(" " + i);
			}
			else if (String.valueOf(i).contains("3")) {
				System.out.print(" " + i);
			}
		}
		System.out.println("");
	} main {

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

		for (int i = 1; i <= v; i++) {
			if (i % 3 == 0) {
				System.out.print(" " + i);
			}
			else if (String.valueOf(i).contains("3")) {
				System.out.print(" " + i);
			}
		}
		System.out.println("");
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String line = sc.nextLine(); line sc.nextLine() sc.nextLine sc int v = Integer.parseInt(line); v Integer.parseInt(line) Integer.parseInt Integer line for (int i = 1; i <= v; i++) {
			if (i % 3 == 0) {
				System.out.print(" " + i);
			}
			else if (String.valueOf(i).contains("3")) {
				System.out.print(" " + i);
			}
		} int i = 1; int i = 1; i 1 i <= v i v i++ i++ i {
			if (i % 3 == 0) {
				System.out.print(" " + i);
			}
			else if (String.valueOf(i).contains("3")) {
				System.out.print(" " + i);
			}
		} {
			if (i % 3 == 0) {
				System.out.print(" " + i);
			}
			else if (String.valueOf(i).contains("3")) {
				System.out.print(" " + i);
			}
		} if (i % 3 == 0) {
				System.out.print(" " + i);
			}
			else if (String.valueOf(i).contains("3")) {
				System.out.print(" " + i);
			} i % 3 == 0 i % 3 i 3 0 {
				System.out.print(" " + i);
			} System.out.print(" " + i) System.out.print System.out System System.out " " + i " " i if (String.valueOf(i).contains("3")) {
				System.out.print(" " + i);
			} String.valueOf(i).contains("3") String.valueOf(i).contains String.valueOf(i) String.valueOf String i "3" {
				System.out.print(" " + i);
			} System.out.print(" " + i) System.out.print System.out System System.out " " + i " " i System.out.println("") System.out.println System.out System System.out "" String[] arges arges public class Main {
	public static void main(String[] arges) {

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

		for (int i = 1; i <= v; i++) {
			if (i % 3 == 0) {
				System.out.print(" " + i);
			}
			else if (String.valueOf(i).contains("3")) {
				System.out.print(" " + i);
			}
		}
		System.out.println("");
	}
} public class Main {
	public static void main(String[] arges) {

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

		for (int i = 1; i <= v; i++) {
			if (i % 3 == 0) {
				System.out.print(" " + i);
			}
			else if (String.valueOf(i).contains("3")) {
				System.out.print(" " + i);
			}
		}
		System.out.println("");
	}
} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] arges) {

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

		for (int i = 1; i <= v; i++) {
			if (i % 3 == 0) {
				System.out.print(" " + i);
			}
			else if (String.valueOf(i).contains("3")) {
				System.out.print(" " + i);
			}
		}
		System.out.println("");
	}
}