import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		int num = Integer.parseInt(line);

		StringBuilder ans = new StringBuilder();
		int x = 3;
		for (int i = 3; i <= num; i++) {

			if (i % 3 == 0  || i % 10 == 3) {
				ans.append(" " + i);

			} else{
				while ( x >= 1 ) {
					if (x %10 == 3) {
						ans.append(" " + i);
						break;
					}
					x/=10;
				}

			}
			x = i;
			x ++;
		}

		String d = ans.toString();
		System.out.println(d);
	}

//330番台がかぶっているのでそれをなんとかする
}
 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 num = Integer.parseInt(line);

		StringBuilder ans = new StringBuilder();
		int x = 3;
		for (int i = 3; i <= num; i++) {

			if (i % 3 == 0  || i % 10 == 3) {
				ans.append(" " + i);

			} else{
				while ( x >= 1 ) {
					if (x %10 == 3) {
						ans.append(" " + i);
						break;
					}
					x/=10;
				}

			}
			x = i;
			x ++;
		}

		String d = ans.toString();
		System.out.println(d);
	}

//330番台がかぶっているのでそれをなんとかする
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		int num = Integer.parseInt(line);

		StringBuilder ans = new StringBuilder();
		int x = 3;
		for (int i = 3; i <= num; i++) {

			if (i % 3 == 0  || i % 10 == 3) {
				ans.append(" " + i);

			} else{
				while ( x >= 1 ) {
					if (x %10 == 3) {
						ans.append(" " + i);
						break;
					}
					x/=10;
				}

			}
			x = i;
			x ++;
		}

		String d = ans.toString();
		System.out.println(d);
	} main {
		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		int num = Integer.parseInt(line);

		StringBuilder ans = new StringBuilder();
		int x = 3;
		for (int i = 3; i <= num; i++) {

			if (i % 3 == 0  || i % 10 == 3) {
				ans.append(" " + i);

			} else{
				while ( x >= 1 ) {
					if (x %10 == 3) {
						ans.append(" " + i);
						break;
					}
					x/=10;
				}

			}
			x = i;
			x ++;
		}

		String d = ans.toString();
		System.out.println(d);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String line = sc.nextLine(); line sc.nextLine() sc.nextLine sc int num = Integer.parseInt(line); num Integer.parseInt(line) Integer.parseInt Integer line StringBuilder ans = new StringBuilder(); ans new StringBuilder() int x = 3; x 3 for (int i = 3; i <= num; i++) {

			if (i % 3 == 0  || i % 10 == 3) {
				ans.append(" " + i);

			} else{
				while ( x >= 1 ) {
					if (x %10 == 3) {
						ans.append(" " + i);
						break;
					}
					x/=10;
				}

			}
			x = i;
			x ++;
		} int i = 3; int i = 3; i 3 i <= num i num i++ i++ i {

			if (i % 3 == 0  || i % 10 == 3) {
				ans.append(" " + i);

			} else{
				while ( x >= 1 ) {
					if (x %10 == 3) {
						ans.append(" " + i);
						break;
					}
					x/=10;
				}

			}
			x = i;
			x ++;
		} {

			if (i % 3 == 0  || i % 10 == 3) {
				ans.append(" " + i);

			} else{
				while ( x >= 1 ) {
					if (x %10 == 3) {
						ans.append(" " + i);
						break;
					}
					x/=10;
				}

			}
			x = i;
			x ++;
		} if (i % 3 == 0  || i % 10 == 3) {
				ans.append(" " + i);

			} else{
				while ( x >= 1 ) {
					if (x %10 == 3) {
						ans.append(" " + i);
						break;
					}
					x/=10;
				}

			} i % 3 == 0  || i % 10 == 3 i % 3 == 0 i % 3 i 3 0 i % 10 == 3 i % 10 i 10 3 {
				ans.append(" " + i);

			} ans.append(" " + i) ans.append ans " " + i " " i {
				while ( x >= 1 ) {
					if (x %10 == 3) {
						ans.append(" " + i);
						break;
					}
					x/=10;
				}

			} while ( x >= 1 ) {
					if (x %10 == 3) {
						ans.append(" " + i);
						break;
					}
					x/=10;
				} x >= 1 x 1 {
					if (x %10 == 3) {
						ans.append(" " + i);
						break;
					}
					x/=10;
				} if (x %10 == 3) {
						ans.append(" " + i);
						break;
					} x %10 == 3 x %10 x 10 3 {
						ans.append(" " + i);
						break;
					} ans.append(" " + i) ans.append ans " " + i " " i break; x/=10 x 10 x = i x i x ++ x String d = ans.toString(); d ans.toString() ans.toString ans System.out.println(d) System.out.println System.out System System.out d String[] args args public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		int num = Integer.parseInt(line);

		StringBuilder ans = new StringBuilder();
		int x = 3;
		for (int i = 3; i <= num; i++) {

			if (i % 3 == 0  || i % 10 == 3) {
				ans.append(" " + i);

			} else{
				while ( x >= 1 ) {
					if (x %10 == 3) {
						ans.append(" " + i);
						break;
					}
					x/=10;
				}

			}
			x = i;
			x ++;
		}

		String d = ans.toString();
		System.out.println(d);
	}

//330番台がかぶっているのでそれをなんとかする
} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		int num = Integer.parseInt(line);

		StringBuilder ans = new StringBuilder();
		int x = 3;
		for (int i = 3; i <= num; i++) {

			if (i % 3 == 0  || i % 10 == 3) {
				ans.append(" " + i);

			} else{
				while ( x >= 1 ) {
					if (x %10 == 3) {
						ans.append(" " + i);
						break;
					}
					x/=10;
				}

			}
			x = i;
			x ++;
		}

		String d = ans.toString();
		System.out.println(d);
	}

//330番台がかぶっているのでそれをなんとかする
} 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 num = Integer.parseInt(line);

		StringBuilder ans = new StringBuilder();
		int x = 3;
		for (int i = 3; i <= num; i++) {

			if (i % 3 == 0  || i % 10 == 3) {
				ans.append(" " + i);

			} else{
				while ( x >= 1 ) {
					if (x %10 == 3) {
						ans.append(" " + i);
						break;
					}
					x/=10;
				}

			}
			x = i;
			x ++;
		}

		String d = ans.toString();
		System.out.println(d);
	}

//330番台がかぶっているのでそれをなんとかする
}

