import java.util.Scanner;

class Main {
	public static void main(String[] args) throws Exception {
		int n = new Scanner(System.in).nextInt();
		int i=1;
		do{
			int x=i;
			if(x%3==0){
				System.out.print(" "+i);
			}else{
				if(x/1000==3||x%1000/100==3||x%1000%100/10==3||x%1000%100%10==3||
					x/100==3||x%100/10==3||x%100%10==3||x/10==3||x%10==3){
					System.out.print(" "+i);
				}
			}
		}while(++i<=n);
		System.out.println("");
	}
} import java.util.Scanner; Scanner java.util class Main {
	public static void main(String[] args) throws Exception {
		int n = new Scanner(System.in).nextInt();
		int i=1;
		do{
			int x=i;
			if(x%3==0){
				System.out.print(" "+i);
			}else{
				if(x/1000==3||x%1000/100==3||x%1000%100/10==3||x%1000%100%10==3||
					x/100==3||x%100/10==3||x%100%10==3||x/10==3||x%10==3){
					System.out.print(" "+i);
				}
			}
		}while(++i<=n);
		System.out.println("");
	}
} Main public static void main(String[] args) throws Exception {
		int n = new Scanner(System.in).nextInt();
		int i=1;
		do{
			int x=i;
			if(x%3==0){
				System.out.print(" "+i);
			}else{
				if(x/1000==3||x%1000/100==3||x%1000%100/10==3||x%1000%100%10==3||
					x/100==3||x%100/10==3||x%100%10==3||x/10==3||x%10==3){
					System.out.print(" "+i);
				}
			}
		}while(++i<=n);
		System.out.println("");
	} main {
		int n = new Scanner(System.in).nextInt();
		int i=1;
		do{
			int x=i;
			if(x%3==0){
				System.out.print(" "+i);
			}else{
				if(x/1000==3||x%1000/100==3||x%1000%100/10==3||x%1000%100%10==3||
					x/100==3||x%100/10==3||x%100%10==3||x/10==3||x%10==3){
					System.out.print(" "+i);
				}
			}
		}while(++i<=n);
		System.out.println("");
	} int n = new Scanner(System.in).nextInt(); n new Scanner(System.in).nextInt() new Scanner(System.in).nextInt new Scanner(System.in) int i=1; i 1 do{
			int x=i;
			if(x%3==0){
				System.out.print(" "+i);
			}else{
				if(x/1000==3||x%1000/100==3||x%1000%100/10==3||x%1000%100%10==3||
					x/100==3||x%100/10==3||x%100%10==3||x/10==3||x%10==3){
					System.out.print(" "+i);
				}
			}
		}while(++i<=n); ++i<=n ++i i n {
			int x=i;
			if(x%3==0){
				System.out.print(" "+i);
			}else{
				if(x/1000==3||x%1000/100==3||x%1000%100/10==3||x%1000%100%10==3||
					x/100==3||x%100/10==3||x%100%10==3||x/10==3||x%10==3){
					System.out.print(" "+i);
				}
			}
		} int x=i; x i if(x%3==0){
				System.out.print(" "+i);
			}else{
				if(x/1000==3||x%1000/100==3||x%1000%100/10==3||x%1000%100%10==3||
					x/100==3||x%100/10==3||x%100%10==3||x/10==3||x%10==3){
					System.out.print(" "+i);
				}
			} 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 {
				if(x/1000==3||x%1000/100==3||x%1000%100/10==3||x%1000%100%10==3||
					x/100==3||x%100/10==3||x%100%10==3||x/10==3||x%10==3){
					System.out.print(" "+i);
				}
			} if(x/1000==3||x%1000/100==3||x%1000%100/10==3||x%1000%100%10==3||
					x/100==3||x%100/10==3||x%100%10==3||x/10==3||x%10==3){
					System.out.print(" "+i);
				} x/1000==3||x%1000/100==3||x%1000%100/10==3||x%1000%100%10==3||
					x/100==3||x%100/10==3||x%100%10==3||x/10==3||x%10==3 x/10==3 x%100%10==3 x%100/10==3 x/100==3 x%1000%100%10==3 x%1000%100/10==3 x/1000==3||x%1000/100==3||x%1000%100/10==3||x%1000%100%10==3||
					x/100==3||x%100/10==3||x%100%10==3||x/10==3||x%10==3 x/1000==3 x/1000 x 1000 3 x%1000/100==3 x%1000/100 x%1000 x 1000 100 3 x%1000%100/10==3 x%1000%100/10 x%1000%100 x%1000%100 x 1000 100 10 3 x%1000%100%10==3 x%1000%100%10 100 x%1000%100%10 x 1000 100 10 3 x/100==3 x/100 x 100 3 x%100/10==3 x%100/10 x%100 x 100 10 3 x%100%10==3 x%100%10 x%100%10 x 100 10 3 x/10==3 x/10 x 10 3 x%10==3 x%10 x 10 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
import java.util.Scanner;

class Main {
	public static void main(String[] args) throws Exception {
		int n = new Scanner(System.in).nextInt();
		int i=1;
		do{
			int x=i;
			if(x%3==0){
				System.out.print(" "+i);
			}else{
				if(x/1000==3||x%1000/100==3||x%1000%100/10==3||x%1000%100%10==3||
					x/100==3||x%100/10==3||x%100%10==3||x/10==3||x%10==3){
					System.out.print(" "+i);
				}
			}
		}while(++i<=n);
		System.out.println("");
	}
}