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