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