import java.util.Scanner;


public class Main {


	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n =scan.nextInt();

		for(int i=3;i<=n;i++){
			if(i%3 == 0){
				System.out.print(" "+i);
			}else{

			int a = i;
			if(a/1000 == 3){
				System.out.print(" "+i);
			}else{
				a =a - a/1000 *1000;
				if(a/100==3){
					System.out.print(" "+i);
				}else{
						a =a - a/100 *100;
						if(a/10==3){
							System.out.print(" "+i);
						}else{
							a = a -a/10*10;
							if(a==3){
								System.out.print(" "+i);

							}
						}
					}
				}
			}
		}


		System.out.println();
	}
} import java.util.Scanner; Scanner java.util public class Main {


	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n =scan.nextInt();

		for(int i=3;i<=n;i++){
			if(i%3 == 0){
				System.out.print(" "+i);
			}else{

			int a = i;
			if(a/1000 == 3){
				System.out.print(" "+i);
			}else{
				a =a - a/1000 *1000;
				if(a/100==3){
					System.out.print(" "+i);
				}else{
						a =a - a/100 *100;
						if(a/10==3){
							System.out.print(" "+i);
						}else{
							a = a -a/10*10;
							if(a==3){
								System.out.print(" "+i);

							}
						}
					}
				}
			}
		}


		System.out.println();
	}
} Main public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n =scan.nextInt();

		for(int i=3;i<=n;i++){
			if(i%3 == 0){
				System.out.print(" "+i);
			}else{

			int a = i;
			if(a/1000 == 3){
				System.out.print(" "+i);
			}else{
				a =a - a/1000 *1000;
				if(a/100==3){
					System.out.print(" "+i);
				}else{
						a =a - a/100 *100;
						if(a/10==3){
							System.out.print(" "+i);
						}else{
							a = a -a/10*10;
							if(a==3){
								System.out.print(" "+i);

							}
						}
					}
				}
			}
		}


		System.out.println();
	} main {
		Scanner scan = new Scanner(System.in);
		int n =scan.nextInt();

		for(int i=3;i<=n;i++){
			if(i%3 == 0){
				System.out.print(" "+i);
			}else{

			int a = i;
			if(a/1000 == 3){
				System.out.print(" "+i);
			}else{
				a =a - a/1000 *1000;
				if(a/100==3){
					System.out.print(" "+i);
				}else{
						a =a - a/100 *100;
						if(a/10==3){
							System.out.print(" "+i);
						}else{
							a = a -a/10*10;
							if(a==3){
								System.out.print(" "+i);

							}
						}
					}
				}
			}
		}


		System.out.println();
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int n =scan.nextInt(); n scan.nextInt() scan.nextInt scan for(int i=3;i<=n;i++){
			if(i%3 == 0){
				System.out.print(" "+i);
			}else{

			int a = i;
			if(a/1000 == 3){
				System.out.print(" "+i);
			}else{
				a =a - a/1000 *1000;
				if(a/100==3){
					System.out.print(" "+i);
				}else{
						a =a - a/100 *100;
						if(a/10==3){
							System.out.print(" "+i);
						}else{
							a = a -a/10*10;
							if(a==3){
								System.out.print(" "+i);

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

			int a = i;
			if(a/1000 == 3){
				System.out.print(" "+i);
			}else{
				a =a - a/1000 *1000;
				if(a/100==3){
					System.out.print(" "+i);
				}else{
						a =a - a/100 *100;
						if(a/10==3){
							System.out.print(" "+i);
						}else{
							a = a -a/10*10;
							if(a==3){
								System.out.print(" "+i);

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

			int a = i;
			if(a/1000 == 3){
				System.out.print(" "+i);
			}else{
				a =a - a/1000 *1000;
				if(a/100==3){
					System.out.print(" "+i);
				}else{
						a =a - a/100 *100;
						if(a/10==3){
							System.out.print(" "+i);
						}else{
							a = a -a/10*10;
							if(a==3){
								System.out.print(" "+i);

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

			int a = i;
			if(a/1000 == 3){
				System.out.print(" "+i);
			}else{
				a =a - a/1000 *1000;
				if(a/100==3){
					System.out.print(" "+i);
				}else{
						a =a - a/100 *100;
						if(a/10==3){
							System.out.print(" "+i);
						}else{
							a = a -a/10*10;
							if(a==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 {

			int a = i;
			if(a/1000 == 3){
				System.out.print(" "+i);
			}else{
				a =a - a/1000 *1000;
				if(a/100==3){
					System.out.print(" "+i);
				}else{
						a =a - a/100 *100;
						if(a/10==3){
							System.out.print(" "+i);
						}else{
							a = a -a/10*10;
							if(a==3){
								System.out.print(" "+i);

							}
						}
					}
				}
			} int a = i; a i if(a/1000 == 3){
				System.out.print(" "+i);
			}else{
				a =a - a/1000 *1000;
				if(a/100==3){
					System.out.print(" "+i);
				}else{
						a =a - a/100 *100;
						if(a/10==3){
							System.out.print(" "+i);
						}else{
							a = a -a/10*10;
							if(a==3){
								System.out.print(" "+i);

							}
						}
					}
				} a/1000 == 3 a/1000 a 1000 3 {
				System.out.print(" "+i);
			} System.out.print(" "+i) System.out.print System.out System System.out " "+i " " i {
				a =a - a/1000 *1000;
				if(a/100==3){
					System.out.print(" "+i);
				}else{
						a =a - a/100 *100;
						if(a/10==3){
							System.out.print(" "+i);
						}else{
							a = a -a/10*10;
							if(a==3){
								System.out.print(" "+i);

							}
						}
					}
				} a =a - a/1000 *1000 a a - a/1000 *1000 a a/1000 *1000 a/1000 a 1000 1000 if(a/100==3){
					System.out.print(" "+i);
				}else{
						a =a - a/100 *100;
						if(a/10==3){
							System.out.print(" "+i);
						}else{
							a = a -a/10*10;
							if(a==3){
								System.out.print(" "+i);

							}
						}
					} a/100==3 a/100 a 100 3 {
					System.out.print(" "+i);
				} System.out.print(" "+i) System.out.print System.out System System.out " "+i " " i {
						a =a - a/100 *100;
						if(a/10==3){
							System.out.print(" "+i);
						}else{
							a = a -a/10*10;
							if(a==3){
								System.out.print(" "+i);

							}
						}
					} a =a - a/100 *100 a a - a/100 *100 a a/100 *100 a/100 a 100 100 if(a/10==3){
							System.out.print(" "+i);
						}else{
							a = a -a/10*10;
							if(a==3){
								System.out.print(" "+i);

							}
						} a/10==3 a/10 a 10 3 {
							System.out.print(" "+i);
						} System.out.print(" "+i) System.out.print System.out System System.out " "+i " " i {
							a = a -a/10*10;
							if(a==3){
								System.out.print(" "+i);

							}
						} a = a -a/10*10 a a -a/10*10 a a/10*10 a/10 a 10 10 if(a==3){
								System.out.print(" "+i);

							} a==3 a 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[] args args public class Main {


	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n =scan.nextInt();

		for(int i=3;i<=n;i++){
			if(i%3 == 0){
				System.out.print(" "+i);
			}else{

			int a = i;
			if(a/1000 == 3){
				System.out.print(" "+i);
			}else{
				a =a - a/1000 *1000;
				if(a/100==3){
					System.out.print(" "+i);
				}else{
						a =a - a/100 *100;
						if(a/10==3){
							System.out.print(" "+i);
						}else{
							a = a -a/10*10;
							if(a==3){
								System.out.print(" "+i);

							}
						}
					}
				}
			}
		}


		System.out.println();
	}
} public class Main {


	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n =scan.nextInt();

		for(int i=3;i<=n;i++){
			if(i%3 == 0){
				System.out.print(" "+i);
			}else{

			int a = i;
			if(a/1000 == 3){
				System.out.print(" "+i);
			}else{
				a =a - a/1000 *1000;
				if(a/100==3){
					System.out.print(" "+i);
				}else{
						a =a - a/100 *100;
						if(a/10==3){
							System.out.print(" "+i);
						}else{
							a = a -a/10*10;
							if(a==3){
								System.out.print(" "+i);

							}
						}
					}
				}
			}
		}


		System.out.println();
	}
} Main
import java.util.Scanner;


public class Main {


	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n =scan.nextInt();

		for(int i=3;i<=n;i++){
			if(i%3 == 0){
				System.out.print(" "+i);
			}else{

			int a = i;
			if(a/1000 == 3){
				System.out.print(" "+i);
			}else{
				a =a - a/1000 *1000;
				if(a/100==3){
					System.out.print(" "+i);
				}else{
						a =a - a/100 *100;
						if(a/10==3){
							System.out.print(" "+i);
						}else{
							a = a -a/10*10;
							if(a==3){
								System.out.print(" "+i);

							}
						}
					}
				}
			}
		}


		System.out.println();
	}
}