import java.util.Scanner;
class Main
{
public static void main(String[] args)
 {
 Scanner sc = new Scanner(System.in);
  int i, n, x;
  n = sc.nextInt();     
  for(i =1; i<=n; i++){
   x = i;
   if(x % 3 == 0){
    System.out.printf(" %d", i);
    continue;
   }
   do{
    if(x % 10 == 3){
    System.out.printf(" %d", i);
    break;
   }
   x /= 10;
   }while(0 < x);
}
   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 i, n, x;
  n = sc.nextInt();     
  for(i =1; i<=n; i++){
   x = i;
   if(x % 3 == 0){
    System.out.printf(" %d", i);
    continue;
   }
   do{
    if(x % 10 == 3){
    System.out.printf(" %d", i);
    break;
   }
   x /= 10;
   }while(0 < x);
}
   System.out.println();
}  
} Main public static void main(String[] args)
 {
 Scanner sc = new Scanner(System.in);
  int i, n, x;
  n = sc.nextInt();     
  for(i =1; i<=n; i++){
   x = i;
   if(x % 3 == 0){
    System.out.printf(" %d", i);
    continue;
   }
   do{
    if(x % 10 == 3){
    System.out.printf(" %d", i);
    break;
   }
   x /= 10;
   }while(0 < x);
}
   System.out.println();
} main {
 Scanner sc = new Scanner(System.in);
  int i, n, x;
  n = sc.nextInt();     
  for(i =1; i<=n; i++){
   x = i;
   if(x % 3 == 0){
    System.out.printf(" %d", i);
    continue;
   }
   do{
    if(x % 10 == 3){
    System.out.printf(" %d", i);
    break;
   }
   x /= 10;
   }while(0 < x);
}
   System.out.println();
} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int i i n n x; x n = sc.nextInt() n sc.nextInt() sc.nextInt sc for(i =1; i<=n; i++){
   x = i;
   if(x % 3 == 0){
    System.out.printf(" %d", i);
    continue;
   }
   do{
    if(x % 10 == 3){
    System.out.printf(" %d", i);
    break;
   }
   x /= 10;
   }while(0 < x);
} i =1; i =1 i 1 i<=n i n i++ i++ i {
   x = i;
   if(x % 3 == 0){
    System.out.printf(" %d", i);
    continue;
   }
   do{
    if(x % 10 == 3){
    System.out.printf(" %d", i);
    break;
   }
   x /= 10;
   }while(0 < x);
} {
   x = i;
   if(x % 3 == 0){
    System.out.printf(" %d", i);
    continue;
   }
   do{
    if(x % 10 == 3){
    System.out.printf(" %d", i);
    break;
   }
   x /= 10;
   }while(0 < x);
} x = i x i if(x % 3 == 0){
    System.out.printf(" %d", i);
    continue;
   } x % 3 == 0 x % 3 x 3 0 {
    System.out.printf(" %d", i);
    continue;
   } System.out.printf(" %d", i) System.out.printf System.out System System.out " %d" i continue; do{
    if(x % 10 == 3){
    System.out.printf(" %d", i);
    break;
   }
   x /= 10;
   }while(0 < x); 0 < x 0 x {
    if(x % 10 == 3){
    System.out.printf(" %d", i);
    break;
   }
   x /= 10;
   } if(x % 10 == 3){
    System.out.printf(" %d", i);
    break;
   } x % 10 == 3 x % 10 x 10 3 {
    System.out.printf(" %d", i);
    break;
   } System.out.printf(" %d", i) System.out.printf System.out System System.out " %d" i break; x /= 10 x 10 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 i, n, x;
  n = sc.nextInt();     
  for(i =1; i<=n; i++){
   x = i;
   if(x % 3 == 0){
    System.out.printf(" %d", i);
    continue;
   }
   do{
    if(x % 10 == 3){
    System.out.printf(" %d", i);
    break;
   }
   x /= 10;
   }while(0 < x);
}
   System.out.println();
}  
}

