import java.util.Scanner;

public class Main{
 public static void main(String[] args){
  
  Scanner num = new Scanner(System.in);
  int n = num.nextInt();
  int i=1;
  
  while(true){
   
   String three = "" + i;
   int x=i;
   if(x%3 == 0 || three.contains("3")){
    System.out.printf(" %d",i);
   }
   i++;
   if(i > n) break;
  }
  
  System.out.println();
 }
} import java.util.Scanner; Scanner java.util public class Main{
 public static void main(String[] args){
  
  Scanner num = new Scanner(System.in);
  int n = num.nextInt();
  int i=1;
  
  while(true){
   
   String three = "" + i;
   int x=i;
   if(x%3 == 0 || three.contains("3")){
    System.out.printf(" %d",i);
   }
   i++;
   if(i > n) break;
  }
  
  System.out.println();
 }
} Main public static void main(String[] args){
  
  Scanner num = new Scanner(System.in);
  int n = num.nextInt();
  int i=1;
  
  while(true){
   
   String three = "" + i;
   int x=i;
   if(x%3 == 0 || three.contains("3")){
    System.out.printf(" %d",i);
   }
   i++;
   if(i > n) break;
  }
  
  System.out.println();
 } main {
  
  Scanner num = new Scanner(System.in);
  int n = num.nextInt();
  int i=1;
  
  while(true){
   
   String three = "" + i;
   int x=i;
   if(x%3 == 0 || three.contains("3")){
    System.out.printf(" %d",i);
   }
   i++;
   if(i > n) break;
  }
  
  System.out.println();
 } Scanner num = new Scanner(System.in); num new Scanner(System.in) int n = num.nextInt(); n num.nextInt() num.nextInt num int i=1; i 1 while(true){
   
   String three = "" + i;
   int x=i;
   if(x%3 == 0 || three.contains("3")){
    System.out.printf(" %d",i);
   }
   i++;
   if(i > n) break;
  } true {
   
   String three = "" + i;
   int x=i;
   if(x%3 == 0 || three.contains("3")){
    System.out.printf(" %d",i);
   }
   i++;
   if(i > n) break;
  } String three = "" + i; three "" + i "" i int x=i; x i if(x%3 == 0 || three.contains("3")){
    System.out.printf(" %d",i);
   } x%3 == 0 || three.contains("3") x%3 == 0 x%3 x 3 0 three.contains("3") three.contains three "3" {
    System.out.printf(" %d",i);
   } System.out.printf(" %d",i) System.out.printf System.out System System.out " %d" i i++ i if(i > n) break; i > n i n break; System.out.println() System.out.println System.out System System.out String[] args args public class Main{
 public static void main(String[] args){
  
  Scanner num = new Scanner(System.in);
  int n = num.nextInt();
  int i=1;
  
  while(true){
   
   String three = "" + i;
   int x=i;
   if(x%3 == 0 || three.contains("3")){
    System.out.printf(" %d",i);
   }
   i++;
   if(i > n) break;
  }
  
  System.out.println();
 }
} public class Main{
 public static void main(String[] args){
  
  Scanner num = new Scanner(System.in);
  int n = num.nextInt();
  int i=1;
  
  while(true){
   
   String three = "" + i;
   int x=i;
   if(x%3 == 0 || three.contains("3")){
    System.out.printf(" %d",i);
   }
   i++;
   if(i > n) break;
  }
  
  System.out.println();
 }
} Main
import java.util.Scanner;

public class Main{
 public static void main(String[] args){
  
  Scanner num = new Scanner(System.in);
  int n = num.nextInt();
  int i=1;
  
  while(true){
   
   String three = "" + i;
   int x=i;
   if(x%3 == 0 || three.contains("3")){
    System.out.printf(" %d",i);
   }
   i++;
   if(i > n) break;
  }
  
  System.out.println();
 }
}