import java.io.*;

class Main{
 public static void main(String[] args)throws IOException{
 BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); 
 int x,i,tmp;
 StringBuilder sb = new StringBuilder();
 
 x = Integer.parseInt(br.readLine());
  for(i=1;i<=x;i++){
   if(i%3==0){
    sb.append(" "+i);
   }else{
   tmp=i;
    while(tmp!=0){
      if(tmp%10==3){    
       sb.append(" "+i);  
       break;    
      }
     tmp =tmp/10; 
    }
   }
  }
  System.out.println(sb); 
  
 }
} import java.io.*; io.* java class Main{
 public static void main(String[] args)throws IOException{
 BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); 
 int x,i,tmp;
 StringBuilder sb = new StringBuilder();
 
 x = Integer.parseInt(br.readLine());
  for(i=1;i<=x;i++){
   if(i%3==0){
    sb.append(" "+i);
   }else{
   tmp=i;
    while(tmp!=0){
      if(tmp%10==3){    
       sb.append(" "+i);  
       break;    
      }
     tmp =tmp/10; 
    }
   }
  }
  System.out.println(sb); 
  
 }
} Main public static void main(String[] args)throws IOException{
 BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); 
 int x,i,tmp;
 StringBuilder sb = new StringBuilder();
 
 x = Integer.parseInt(br.readLine());
  for(i=1;i<=x;i++){
   if(i%3==0){
    sb.append(" "+i);
   }else{
   tmp=i;
    while(tmp!=0){
      if(tmp%10==3){    
       sb.append(" "+i);  
       break;    
      }
     tmp =tmp/10; 
    }
   }
  }
  System.out.println(sb); 
  
 } main {
 BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); 
 int x,i,tmp;
 StringBuilder sb = new StringBuilder();
 
 x = Integer.parseInt(br.readLine());
  for(i=1;i<=x;i++){
   if(i%3==0){
    sb.append(" "+i);
   }else{
   tmp=i;
    while(tmp!=0){
      if(tmp%10==3){    
       sb.append(" "+i);  
       break;    
      }
     tmp =tmp/10; 
    }
   }
  }
  System.out.println(sb); 
  
 } BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) int x x i i tmp; tmp StringBuilder sb = new StringBuilder(); sb new StringBuilder() x = Integer.parseInt(br.readLine()) x Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br for(i=1;i<=x;i++){
   if(i%3==0){
    sb.append(" "+i);
   }else{
   tmp=i;
    while(tmp!=0){
      if(tmp%10==3){    
       sb.append(" "+i);  
       break;    
      }
     tmp =tmp/10; 
    }
   }
  } i=1; i=1 i 1 i<=x i x i++ i++ i {
   if(i%3==0){
    sb.append(" "+i);
   }else{
   tmp=i;
    while(tmp!=0){
      if(tmp%10==3){    
       sb.append(" "+i);  
       break;    
      }
     tmp =tmp/10; 
    }
   }
  } {
   if(i%3==0){
    sb.append(" "+i);
   }else{
   tmp=i;
    while(tmp!=0){
      if(tmp%10==3){    
       sb.append(" "+i);  
       break;    
      }
     tmp =tmp/10; 
    }
   }
  } if(i%3==0){
    sb.append(" "+i);
   }else{
   tmp=i;
    while(tmp!=0){
      if(tmp%10==3){    
       sb.append(" "+i);  
       break;    
      }
     tmp =tmp/10; 
    }
   } i%3==0 i%3 i 3 0 {
    sb.append(" "+i);
   } sb.append(" "+i) sb.append sb " "+i " " i {
   tmp=i;
    while(tmp!=0){
      if(tmp%10==3){    
       sb.append(" "+i);  
       break;    
      }
     tmp =tmp/10; 
    }
   } tmp=i tmp i while(tmp!=0){
      if(tmp%10==3){    
       sb.append(" "+i);  
       break;    
      }
     tmp =tmp/10; 
    } tmp!=0 tmp 0 {
      if(tmp%10==3){    
       sb.append(" "+i);  
       break;    
      }
     tmp =tmp/10; 
    } if(tmp%10==3){    
       sb.append(" "+i);  
       break;    
      } tmp%10==3 tmp%10 tmp 10 3 {    
       sb.append(" "+i);  
       break;    
      } sb.append(" "+i) sb.append sb " "+i " " i break; tmp =tmp/10 tmp tmp/10 tmp 10 System.out.println(sb) System.out.println System.out System System.out sb String[] args args
import java.io.*;

class Main{
 public static void main(String[] args)throws IOException{
 BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); 
 int x,i,tmp;
 StringBuilder sb = new StringBuilder();
 
 x = Integer.parseInt(br.readLine());
  for(i=1;i<=x;i++){
   if(i%3==0){
    sb.append(" "+i);
   }else{
   tmp=i;
    while(tmp!=0){
      if(tmp%10==3){    
       sb.append(" "+i);  
       break;    
      }
     tmp =tmp/10; 
    }
   }
  }
  System.out.println(sb); 
  
 }
}