import java.util.InputMismatchException;
import java.util.Scanner;

public class Main{


	public static void main(String[] args){

    	Scanner scan = new Scanner(System.in);

				try{
            int n=scan.nextInt();

            call(n);


				}catch(InputMismatchException e){
					System.out.println("??¨??????:"+e);
				}
        	scan.close();


	}


	public static void call(int n){

		int x;
		for(int i=1;i<n+1;i++){

			if(i%3==0 ||i%10==3){
				System.out.print(" "+i);
			}else if((i/10)>0){
				x=i;
				while(x/10>0){
				x/=10;
				if(x%10==3){
					System.out.print(" "+i);
					break;
				}

				}
			}
			//???????????¶????????????????????????????????????i???10??§???????????¨???
			//i/10>0?????¨???



		}System.out.print('\n');


	}

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


	public static void main(String[] args){

    	Scanner scan = new Scanner(System.in);

				try{
            int n=scan.nextInt();

            call(n);


				}catch(InputMismatchException e){
					System.out.println("??¨??????:"+e);
				}
        	scan.close();


	}


	public static void call(int n){

		int x;
		for(int i=1;i<n+1;i++){

			if(i%3==0 ||i%10==3){
				System.out.print(" "+i);
			}else if((i/10)>0){
				x=i;
				while(x/10>0){
				x/=10;
				if(x%10==3){
					System.out.print(" "+i);
					break;
				}

				}
			}
			//???????????¶????????????????????????????????????i???10??§???????????¨???
			//i/10>0?????¨???



		}System.out.print('\n');


	}

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

    	Scanner scan = new Scanner(System.in);

				try{
            int n=scan.nextInt();

            call(n);


				}catch(InputMismatchException e){
					System.out.println("??¨??????:"+e);
				}
        	scan.close();


	} main {

    	Scanner scan = new Scanner(System.in);

				try{
            int n=scan.nextInt();

            call(n);


				}catch(InputMismatchException e){
					System.out.println("??¨??????:"+e);
				}
        	scan.close();


	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) try{
            int n=scan.nextInt();

            call(n);


				}catch(InputMismatchException e){
					System.out.println("??¨??????:"+e);
				} catch(InputMismatchException e){
					System.out.println("??¨??????:"+e);
				} InputMismatchException e {
					System.out.println("??¨??????:"+e);
				} System.out.println("??¨??????:"+e) System.out.println System.out System System.out "??¨??????:"+e "??¨??????:" e {
            int n=scan.nextInt();

            call(n);


				} int n=scan.nextInt(); n scan.nextInt() scan.nextInt scan call(n) call n scan.close() scan.close scan String[] args args public static void call(int n){

		int x;
		for(int i=1;i<n+1;i++){

			if(i%3==0 ||i%10==3){
				System.out.print(" "+i);
			}else if((i/10)>0){
				x=i;
				while(x/10>0){
				x/=10;
				if(x%10==3){
					System.out.print(" "+i);
					break;
				}

				}
			}
			//???????????¶????????????????????????????????????i???10??§???????????¨???
			//i/10>0?????¨???



		}System.out.print('\n');


	} call {

		int x;
		for(int i=1;i<n+1;i++){

			if(i%3==0 ||i%10==3){
				System.out.print(" "+i);
			}else if((i/10)>0){
				x=i;
				while(x/10>0){
				x/=10;
				if(x%10==3){
					System.out.print(" "+i);
					break;
				}

				}
			}
			//???????????¶????????????????????????????????????i???10??§???????????¨???
			//i/10>0?????¨???



		}System.out.print('\n');


	} int x; x for(int i=1;i<n+1;i++){

			if(i%3==0 ||i%10==3){
				System.out.print(" "+i);
			}else if((i/10)>0){
				x=i;
				while(x/10>0){
				x/=10;
				if(x%10==3){
					System.out.print(" "+i);
					break;
				}

				}
			}
			//???????????¶????????????????????????????????????i???10??§???????????¨???
			//i/10>0?????¨???



		} int i=1; int i=1; i 1 i<n+1 i n+1 n 1 i++ i++ i {

			if(i%3==0 ||i%10==3){
				System.out.print(" "+i);
			}else if((i/10)>0){
				x=i;
				while(x/10>0){
				x/=10;
				if(x%10==3){
					System.out.print(" "+i);
					break;
				}

				}
			}
			//???????????¶????????????????????????????????????i???10??§???????????¨???
			//i/10>0?????¨???



		} {

			if(i%3==0 ||i%10==3){
				System.out.print(" "+i);
			}else if((i/10)>0){
				x=i;
				while(x/10>0){
				x/=10;
				if(x%10==3){
					System.out.print(" "+i);
					break;
				}

				}
			}
			//???????????¶????????????????????????????????????i???10??§???????????¨???
			//i/10>0?????¨???



		} if(i%3==0 ||i%10==3){
				System.out.print(" "+i);
			}else if((i/10)>0){
				x=i;
				while(x/10>0){
				x/=10;
				if(x%10==3){
					System.out.print(" "+i);
					break;
				}

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

				}
			} (i/10)>0 (i/10) i 10 0 {
				x=i;
				while(x/10>0){
				x/=10;
				if(x%10==3){
					System.out.print(" "+i);
					break;
				}

				}
			} x=i x i while(x/10>0){
				x/=10;
				if(x%10==3){
					System.out.print(" "+i);
					break;
				}

				} x/10>0 x/10 x 10 0 {
				x/=10;
				if(x%10==3){
					System.out.print(" "+i);
					break;
				}

				} x/=10 x 10 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; System.out.print('\n') System.out.print System.out System System.out '\n' int n n public class Main{


	public static void main(String[] args){

    	Scanner scan = new Scanner(System.in);

				try{
            int n=scan.nextInt();

            call(n);


				}catch(InputMismatchException e){
					System.out.println("??¨??????:"+e);
				}
        	scan.close();


	}


	public static void call(int n){

		int x;
		for(int i=1;i<n+1;i++){

			if(i%3==0 ||i%10==3){
				System.out.print(" "+i);
			}else if((i/10)>0){
				x=i;
				while(x/10>0){
				x/=10;
				if(x%10==3){
					System.out.print(" "+i);
					break;
				}

				}
			}
			//???????????¶????????????????????????????????????i???10??§???????????¨???
			//i/10>0?????¨???



		}System.out.print('\n');


	}

} public class Main{


	public static void main(String[] args){

    	Scanner scan = new Scanner(System.in);

				try{
            int n=scan.nextInt();

            call(n);


				}catch(InputMismatchException e){
					System.out.println("??¨??????:"+e);
				}
        	scan.close();


	}


	public static void call(int n){

		int x;
		for(int i=1;i<n+1;i++){

			if(i%3==0 ||i%10==3){
				System.out.print(" "+i);
			}else if((i/10)>0){
				x=i;
				while(x/10>0){
				x/=10;
				if(x%10==3){
					System.out.print(" "+i);
					break;
				}

				}
			}
			//???????????¶????????????????????????????????????i???10??§???????????¨???
			//i/10>0?????¨???



		}System.out.print('\n');


	}

} Main
import java.util.InputMismatchException;
import java.util.Scanner;

public class Main{


	public static void main(String[] args){

    	Scanner scan = new Scanner(System.in);

				try{
            int n=scan.nextInt();

            call(n);


				}catch(InputMismatchException e){
					System.out.println("??¨??????:"+e);
				}
        	scan.close();


	}


	public static void call(int n){

		int x;
		for(int i=1;i<n+1;i++){

			if(i%3==0 ||i%10==3){
				System.out.print(" "+i);
			}else if((i/10)>0){
				x=i;
				while(x/10>0){
				x/=10;
				if(x%10==3){
					System.out.print(" "+i);
					break;
				}

				}
			}
			//???????????¶????????????????????????????????????i???10??§???????????¨???
			//i/10>0?????¨???



		}System.out.print('\n');


	}

}