import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

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

		int i = 1;

		while (i <= n) {
			String I = String.valueOf(i);
			if (I.matches(".*3.*")) {
				System.out.print(" " + i);
			}

			else if (i % 3 == 0) {
				System.out.print(" " + i);

			} else if (i % 10 == 3) {
				System.out.print(" " + i);

			}
			i++;
		}
		System.out.println("");
	}

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

	public static void main(String[] args) {

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

		int i = 1;

		while (i <= n) {
			String I = String.valueOf(i);
			if (I.matches(".*3.*")) {
				System.out.print(" " + i);
			}

			else if (i % 3 == 0) {
				System.out.print(" " + i);

			} else if (i % 10 == 3) {
				System.out.print(" " + i);

			}
			i++;
		}
		System.out.println("");
	}

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

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

		int i = 1;

		while (i <= n) {
			String I = String.valueOf(i);
			if (I.matches(".*3.*")) {
				System.out.print(" " + i);
			}

			else if (i % 3 == 0) {
				System.out.print(" " + i);

			} else if (i % 10 == 3) {
				System.out.print(" " + i);

			}
			i++;
		}
		System.out.println("");
	} main {

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

		int i = 1;

		while (i <= n) {
			String I = String.valueOf(i);
			if (I.matches(".*3.*")) {
				System.out.print(" " + i);
			}

			else if (i % 3 == 0) {
				System.out.print(" " + i);

			} else if (i % 10 == 3) {
				System.out.print(" " + i);

			}
			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 n = Integer.parseInt(line); n Integer.parseInt(line) Integer.parseInt Integer line int i = 1; i 1 while (i <= n) {
			String I = String.valueOf(i);
			if (I.matches(".*3.*")) {
				System.out.print(" " + i);
			}

			else if (i % 3 == 0) {
				System.out.print(" " + i);

			} else if (i % 10 == 3) {
				System.out.print(" " + i);

			}
			i++;
		} i <= n i n {
			String I = String.valueOf(i);
			if (I.matches(".*3.*")) {
				System.out.print(" " + i);
			}

			else if (i % 3 == 0) {
				System.out.print(" " + i);

			} else if (i % 10 == 3) {
				System.out.print(" " + i);

			}
			i++;
		} String I = String.valueOf(i); I String.valueOf(i) String.valueOf String i if (I.matches(".*3.*")) {
				System.out.print(" " + i);
			}

			else if (i % 3 == 0) {
				System.out.print(" " + i);

			} else if (i % 10 == 3) {
				System.out.print(" " + i);

			} I.matches(".*3.*") I.matches I ".*3.*" {
				System.out.print(" " + i);
			} System.out.print(" " + i) System.out.print System.out System System.out " " + i " " i if (i % 3 == 0) {
				System.out.print(" " + i);

			} else if (i % 10 == 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 (i % 10 == 3) {
				System.out.print(" " + i);

			} i % 10 == 3 i % 10 i 10 3 {
				System.out.print(" " + i);

			} System.out.print(" " + i) System.out.print System.out System System.out " " + i " " i i++ i System.out.println("") System.out.println System.out System System.out "" String[] args args public class Main {

	public static void main(String[] args) {

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

		int i = 1;

		while (i <= n) {
			String I = String.valueOf(i);
			if (I.matches(".*3.*")) {
				System.out.print(" " + i);
			}

			else if (i % 3 == 0) {
				System.out.print(" " + i);

			} else if (i % 10 == 3) {
				System.out.print(" " + i);

			}
			i++;
		}
		System.out.println("");
	}

} public class Main {

	public static void main(String[] args) {

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

		int i = 1;

		while (i <= n) {
			String I = String.valueOf(i);
			if (I.matches(".*3.*")) {
				System.out.print(" " + i);
			}

			else if (i % 3 == 0) {
				System.out.print(" " + i);

			} else if (i % 10 == 3) {
				System.out.print(" " + i);

			}
			i++;
		}
		System.out.println("");
	}

} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

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

		int i = 1;

		while (i <= n) {
			String I = String.valueOf(i);
			if (I.matches(".*3.*")) {
				System.out.print(" " + i);
			}

			else if (i % 3 == 0) {
				System.out.print(" " + i);

			} else if (i % 10 == 3) {
				System.out.print(" " + i);

			}
			i++;
		}
		System.out.println("");
	}

}