import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) {
		BufferedReader input = new BufferedReader(new InputStreamReader(System.in));


		  try{
				  //????????\???
			  //??\????????????a????????????????????°??¨??????????????????????????°???????±???????
			     String ab = input.readLine();
	             int a=Integer.parseInt(ab);
		         int count=1;

		         //??\??????????????°???a?????§??°?????????
		         for(int i=0; i<a; i++){
		        	 //a????????§??????????????????a?????????

		        	 if(count%3==0){
		        		 System.out.print(" "+count);
		        	 }else{
		        		 //???????????¨?????°????????????
		        		 int x=count;
		        		 //x???????????????????????°??°?????????
		        		 while(x!=0){
		        			if(x%10==3){
		        				System.out.print(" "+count);
		        				break;
		        			}else{
		        				x=x/10;
		        				}

		        		 }
		        	 }
		        	 count++;

		         }
		         System.out.println("");


		    }catch(IOException e) {System.out.println("Exception : " + e);
		    }//?????????

	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {
	public static void main(String[] args) {
		BufferedReader input = new BufferedReader(new InputStreamReader(System.in));


		  try{
				  //????????\???
			  //??\????????????a????????????????????°??¨??????????????????????????°???????±???????
			     String ab = input.readLine();
	             int a=Integer.parseInt(ab);
		         int count=1;

		         //??\??????????????°???a?????§??°?????????
		         for(int i=0; i<a; i++){
		        	 //a????????§??????????????????a?????????

		        	 if(count%3==0){
		        		 System.out.print(" "+count);
		        	 }else{
		        		 //???????????¨?????°????????????
		        		 int x=count;
		        		 //x???????????????????????°??°?????????
		        		 while(x!=0){
		        			if(x%10==3){
		        				System.out.print(" "+count);
		        				break;
		        			}else{
		        				x=x/10;
		        				}

		        		 }
		        	 }
		        	 count++;

		         }
		         System.out.println("");


		    }catch(IOException e) {System.out.println("Exception : " + e);
		    }//?????????

	}
} Main public static void main(String[] args) {
		BufferedReader input = new BufferedReader(new InputStreamReader(System.in));


		  try{
				  //????????\???
			  //??\????????????a????????????????????°??¨??????????????????????????°???????±???????
			     String ab = input.readLine();
	             int a=Integer.parseInt(ab);
		         int count=1;

		         //??\??????????????°???a?????§??°?????????
		         for(int i=0; i<a; i++){
		        	 //a????????§??????????????????a?????????

		        	 if(count%3==0){
		        		 System.out.print(" "+count);
		        	 }else{
		        		 //???????????¨?????°????????????
		        		 int x=count;
		        		 //x???????????????????????°??°?????????
		        		 while(x!=0){
		        			if(x%10==3){
		        				System.out.print(" "+count);
		        				break;
		        			}else{
		        				x=x/10;
		        				}

		        		 }
		        	 }
		        	 count++;

		         }
		         System.out.println("");


		    }catch(IOException e) {System.out.println("Exception : " + e);
		    }//?????????

	} main {
		BufferedReader input = new BufferedReader(new InputStreamReader(System.in));


		  try{
				  //????????\???
			  //??\????????????a????????????????????°??¨??????????????????????????°???????±???????
			     String ab = input.readLine();
	             int a=Integer.parseInt(ab);
		         int count=1;

		         //??\??????????????°???a?????§??°?????????
		         for(int i=0; i<a; i++){
		        	 //a????????§??????????????????a?????????

		        	 if(count%3==0){
		        		 System.out.print(" "+count);
		        	 }else{
		        		 //???????????¨?????°????????????
		        		 int x=count;
		        		 //x???????????????????????°??°?????????
		        		 while(x!=0){
		        			if(x%10==3){
		        				System.out.print(" "+count);
		        				break;
		        			}else{
		        				x=x/10;
		        				}

		        		 }
		        	 }
		        	 count++;

		         }
		         System.out.println("");


		    }catch(IOException e) {System.out.println("Exception : " + e);
		    }//?????????

	} BufferedReader input = new BufferedReader(new InputStreamReader(System.in)); input new BufferedReader(new InputStreamReader(System.in)) try{
				  //????????\???
			  //??\????????????a????????????????????°??¨??????????????????????????°???????±???????
			     String ab = input.readLine();
	             int a=Integer.parseInt(ab);
		         int count=1;

		         //??\??????????????°???a?????§??°?????????
		         for(int i=0; i<a; i++){
		        	 //a????????§??????????????????a?????????

		        	 if(count%3==0){
		        		 System.out.print(" "+count);
		        	 }else{
		        		 //???????????¨?????°????????????
		        		 int x=count;
		        		 //x???????????????????????°??°?????????
		        		 while(x!=0){
		        			if(x%10==3){
		        				System.out.print(" "+count);
		        				break;
		        			}else{
		        				x=x/10;
		        				}

		        		 }
		        	 }
		        	 count++;

		         }
		         System.out.println("");


		    }catch(IOException e) {System.out.println("Exception : " + e);
		    }//????????? catch(IOException e) {System.out.println("Exception : " + e);
		    } IOException e {System.out.println("Exception : " + e);
		    } System.out.println("Exception : " + e) System.out.println System.out System System.out "Exception : " + e "Exception : " e {
				  //????????\???
			  //??\????????????a????????????????????°??¨??????????????????????????°???????±???????
			     String ab = input.readLine();
	             int a=Integer.parseInt(ab);
		         int count=1;

		         //??\??????????????°???a?????§??°?????????
		         for(int i=0; i<a; i++){
		        	 //a????????§??????????????????a?????????

		        	 if(count%3==0){
		        		 System.out.print(" "+count);
		        	 }else{
		        		 //???????????¨?????°????????????
		        		 int x=count;
		        		 //x???????????????????????°??°?????????
		        		 while(x!=0){
		        			if(x%10==3){
		        				System.out.print(" "+count);
		        				break;
		        			}else{
		        				x=x/10;
		        				}

		        		 }
		        	 }
		        	 count++;

		         }
		         System.out.println("");


		    } String ab = input.readLine(); ab input.readLine() input.readLine input int a=Integer.parseInt(ab); a Integer.parseInt(ab) Integer.parseInt Integer ab int count=1; count 1 for(int i=0; i<a; i++){
		        	 //a????????§??????????????????a?????????

		        	 if(count%3==0){
		        		 System.out.print(" "+count);
		        	 }else{
		        		 //???????????¨?????°????????????
		        		 int x=count;
		        		 //x???????????????????????°??°?????????
		        		 while(x!=0){
		        			if(x%10==3){
		        				System.out.print(" "+count);
		        				break;
		        			}else{
		        				x=x/10;
		        				}

		        		 }
		        	 }
		        	 count++;

		         } int i=0; int i=0; i 0 i<a i a i++ i++ i {
		        	 //a????????§??????????????????a?????????

		        	 if(count%3==0){
		        		 System.out.print(" "+count);
		        	 }else{
		        		 //???????????¨?????°????????????
		        		 int x=count;
		        		 //x???????????????????????°??°?????????
		        		 while(x!=0){
		        			if(x%10==3){
		        				System.out.print(" "+count);
		        				break;
		        			}else{
		        				x=x/10;
		        				}

		        		 }
		        	 }
		        	 count++;

		         } {
		        	 //a????????§??????????????????a?????????

		        	 if(count%3==0){
		        		 System.out.print(" "+count);
		        	 }else{
		        		 //???????????¨?????°????????????
		        		 int x=count;
		        		 //x???????????????????????°??°?????????
		        		 while(x!=0){
		        			if(x%10==3){
		        				System.out.print(" "+count);
		        				break;
		        			}else{
		        				x=x/10;
		        				}

		        		 }
		        	 }
		        	 count++;

		         } if(count%3==0){
		        		 System.out.print(" "+count);
		        	 }else{
		        		 //???????????¨?????°????????????
		        		 int x=count;
		        		 //x???????????????????????°??°?????????
		        		 while(x!=0){
		        			if(x%10==3){
		        				System.out.print(" "+count);
		        				break;
		        			}else{
		        				x=x/10;
		        				}

		        		 }
		        	 } count%3==0 count%3 count 3 0 {
		        		 System.out.print(" "+count);
		        	 } System.out.print(" "+count) System.out.print System.out System System.out " "+count " " count {
		        		 //???????????¨?????°????????????
		        		 int x=count;
		        		 //x???????????????????????°??°?????????
		        		 while(x!=0){
		        			if(x%10==3){
		        				System.out.print(" "+count);
		        				break;
		        			}else{
		        				x=x/10;
		        				}

		        		 }
		        	 } int x=count; x count while(x!=0){
		        			if(x%10==3){
		        				System.out.print(" "+count);
		        				break;
		        			}else{
		        				x=x/10;
		        				}

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

		        		 } if(x%10==3){
		        				System.out.print(" "+count);
		        				break;
		        			}else{
		        				x=x/10;
		        				} x%10==3 x%10 x 10 3 {
		        				System.out.print(" "+count);
		        				break;
		        			} System.out.print(" "+count) System.out.print System.out System System.out " "+count " " count break; {
		        				x=x/10;
		        				} x=x/10 x x/10 x 10 count++ count System.out.println("") System.out.println System.out System System.out "" String[] args args public class Main {
	public static void main(String[] args) {
		BufferedReader input = new BufferedReader(new InputStreamReader(System.in));


		  try{
				  //????????\???
			  //??\????????????a????????????????????°??¨??????????????????????????°???????±???????
			     String ab = input.readLine();
	             int a=Integer.parseInt(ab);
		         int count=1;

		         //??\??????????????°???a?????§??°?????????
		         for(int i=0; i<a; i++){
		        	 //a????????§??????????????????a?????????

		        	 if(count%3==0){
		        		 System.out.print(" "+count);
		        	 }else{
		        		 //???????????¨?????°????????????
		        		 int x=count;
		        		 //x???????????????????????°??°?????????
		        		 while(x!=0){
		        			if(x%10==3){
		        				System.out.print(" "+count);
		        				break;
		        			}else{
		        				x=x/10;
		        				}

		        		 }
		        	 }
		        	 count++;

		         }
		         System.out.println("");


		    }catch(IOException e) {System.out.println("Exception : " + e);
		    }//?????????

	}
} public class Main {
	public static void main(String[] args) {
		BufferedReader input = new BufferedReader(new InputStreamReader(System.in));


		  try{
				  //????????\???
			  //??\????????????a????????????????????°??¨??????????????????????????°???????±???????
			     String ab = input.readLine();
	             int a=Integer.parseInt(ab);
		         int count=1;

		         //??\??????????????°???a?????§??°?????????
		         for(int i=0; i<a; i++){
		        	 //a????????§??????????????????a?????????

		        	 if(count%3==0){
		        		 System.out.print(" "+count);
		        	 }else{
		        		 //???????????¨?????°????????????
		        		 int x=count;
		        		 //x???????????????????????°??°?????????
		        		 while(x!=0){
		        			if(x%10==3){
		        				System.out.print(" "+count);
		        				break;
		        			}else{
		        				x=x/10;
		        				}

		        		 }
		        	 }
		        	 count++;

		         }
		         System.out.println("");


		    }catch(IOException e) {System.out.println("Exception : " + e);
		    }//?????????

	}
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) {
		BufferedReader input = new BufferedReader(new InputStreamReader(System.in));


		  try{
				  //????????\???
			  //??\????????????a????????????????????°??¨??????????????????????????°???????±???????
			     String ab = input.readLine();
	             int a=Integer.parseInt(ab);
		         int count=1;

		         //??\??????????????°???a?????§??°?????????
		         for(int i=0; i<a; i++){
		        	 //a????????§??????????????????a?????????

		        	 if(count%3==0){
		        		 System.out.print(" "+count);
		        	 }else{
		        		 //???????????¨?????°????????????
		        		 int x=count;
		        		 //x???????????????????????°??°?????????
		        		 while(x!=0){
		        			if(x%10==3){
		        				System.out.print(" "+count);
		        				break;
		        			}else{
		        				x=x/10;
		        				}

		        		 }
		        	 }
		        	 count++;

		         }
		         System.out.println("");


		    }catch(IOException e) {System.out.println("Exception : " + e);
		    }//?????????

	}
}