import java.util.Scanner;

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