import java.util.Scanner;
public class Main{

	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt();
		int i=1;
		int x;
		while(true){
			x=i;
			if(x%3==0){
				System.out.print(" "+i);
			}else{
				while(true){
					if(x%10==3){
						System.out.print(" "+i);
						break;
					}
					x/=10;
					if(x!=0){
						continue;
					}else{
						break;
					}
				}
			}
			
			if(++i<=n){

			}else{
				System.out.println();
				break;
			}
		}
		scan.close();
	}

} 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();
		int i=1;
		int x;
		while(true){
			x=i;
			if(x%3==0){
				System.out.print(" "+i);
			}else{
				while(true){
					if(x%10==3){
						System.out.print(" "+i);
						break;
					}
					x/=10;
					if(x!=0){
						continue;
					}else{
						break;
					}
				}
			}
			
			if(++i<=n){

			}else{
				System.out.println();
				break;
			}
		}
		scan.close();
	}

} Main public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt();
		int i=1;
		int x;
		while(true){
			x=i;
			if(x%3==0){
				System.out.print(" "+i);
			}else{
				while(true){
					if(x%10==3){
						System.out.print(" "+i);
						break;
					}
					x/=10;
					if(x!=0){
						continue;
					}else{
						break;
					}
				}
			}
			
			if(++i<=n){

			}else{
				System.out.println();
				break;
			}
		}
		scan.close();
	} main {
		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt();
		int i=1;
		int x;
		while(true){
			x=i;
			if(x%3==0){
				System.out.print(" "+i);
			}else{
				while(true){
					if(x%10==3){
						System.out.print(" "+i);
						break;
					}
					x/=10;
					if(x!=0){
						continue;
					}else{
						break;
					}
				}
			}
			
			if(++i<=n){

			}else{
				System.out.println();
				break;
			}
		}
		scan.close();
	} Scanner scan=new Scanner(System.in); scan new Scanner(System.in) int n=scan.nextInt(); n scan.nextInt() scan.nextInt scan int i=1; i 1 int x; x while(true){
			x=i;
			if(x%3==0){
				System.out.print(" "+i);
			}else{
				while(true){
					if(x%10==3){
						System.out.print(" "+i);
						break;
					}
					x/=10;
					if(x!=0){
						continue;
					}else{
						break;
					}
				}
			}
			
			if(++i<=n){

			}else{
				System.out.println();
				break;
			}
		} true {
			x=i;
			if(x%3==0){
				System.out.print(" "+i);
			}else{
				while(true){
					if(x%10==3){
						System.out.print(" "+i);
						break;
					}
					x/=10;
					if(x!=0){
						continue;
					}else{
						break;
					}
				}
			}
			
			if(++i<=n){

			}else{
				System.out.println();
				break;
			}
		} x=i x i if(x%3==0){
				System.out.print(" "+i);
			}else{
				while(true){
					if(x%10==3){
						System.out.print(" "+i);
						break;
					}
					x/=10;
					if(x!=0){
						continue;
					}else{
						break;
					}
				}
			} x%3==0 x%3 x 3 0 {
				System.out.print(" "+i);
			} System.out.print(" "+i) System.out.print System.out System System.out " "+i " " i {
				while(true){
					if(x%10==3){
						System.out.print(" "+i);
						break;
					}
					x/=10;
					if(x!=0){
						continue;
					}else{
						break;
					}
				}
			} while(true){
					if(x%10==3){
						System.out.print(" "+i);
						break;
					}
					x/=10;
					if(x!=0){
						continue;
					}else{
						break;
					}
				} true {
					if(x%10==3){
						System.out.print(" "+i);
						break;
					}
					x/=10;
					if(x!=0){
						continue;
					}else{
						break;
					}
				} if(x%10==3){
						System.out.print(" "+i);
						break;
					} x%10==3 x%10 x 10 3 {
						System.out.print(" "+i);
						break;
					} System.out.print(" "+i) System.out.print System.out System System.out " "+i " " i break; x/=10 x 10 if(x!=0){
						continue;
					}else{
						break;
					} x!=0 x 0 {
						continue;
					} continue; {
						break;
					} break; if(++i<=n){

			}else{
				System.out.println();
				break;
			} ++i<=n ++i i n {

			} {
				System.out.println();
				break;
			} System.out.println() System.out.println System.out System System.out break; scan.close() scan.close scan String[] args args public class Main{

	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt();
		int i=1;
		int x;
		while(true){
			x=i;
			if(x%3==0){
				System.out.print(" "+i);
			}else{
				while(true){
					if(x%10==3){
						System.out.print(" "+i);
						break;
					}
					x/=10;
					if(x!=0){
						continue;
					}else{
						break;
					}
				}
			}
			
			if(++i<=n){

			}else{
				System.out.println();
				break;
			}
		}
		scan.close();
	}

} public class Main{

	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt();
		int i=1;
		int x;
		while(true){
			x=i;
			if(x%3==0){
				System.out.print(" "+i);
			}else{
				while(true){
					if(x%10==3){
						System.out.print(" "+i);
						break;
					}
					x/=10;
					if(x!=0){
						continue;
					}else{
						break;
					}
				}
			}
			
			if(++i<=n){

			}else{
				System.out.println();
				break;
			}
		}
		scan.close();
	}

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

	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt();
		int i=1;
		int x;
		while(true){
			x=i;
			if(x%3==0){
				System.out.print(" "+i);
			}else{
				while(true){
					if(x%10==3){
						System.out.print(" "+i);
						break;
					}
					x/=10;
					if(x!=0){
						continue;
					}else{
						break;
					}
				}
			}
			
			if(++i<=n){

			}else{
				System.out.println();
				break;
			}
		}
		scan.close();
	}

}