import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
 public static void main(String[] args){
	 int n;
	 int k = new java.util.Scanner(System.in).nextInt();
	 String str;
	 Pattern p = Pattern.compile("3");
	
	 for(n=1;n<=k;n++){
		 str  = String.valueOf(n);
		 Matcher m = p.matcher(str);
		 if(n%3==0||m.find()){
			 System.out.print(" "+n);
		 }
		
	 }
	 System.out.println();
 }
} import java.util.regex.Matcher; Matcher java.util.regex import java.util.regex.Pattern; Pattern java.util.regex public class Main {
 public static void main(String[] args){
	 int n;
	 int k = new java.util.Scanner(System.in).nextInt();
	 String str;
	 Pattern p = Pattern.compile("3");
	
	 for(n=1;n<=k;n++){
		 str  = String.valueOf(n);
		 Matcher m = p.matcher(str);
		 if(n%3==0||m.find()){
			 System.out.print(" "+n);
		 }
		
	 }
	 System.out.println();
 }
} Main public static void main(String[] args){
	 int n;
	 int k = new java.util.Scanner(System.in).nextInt();
	 String str;
	 Pattern p = Pattern.compile("3");
	
	 for(n=1;n<=k;n++){
		 str  = String.valueOf(n);
		 Matcher m = p.matcher(str);
		 if(n%3==0||m.find()){
			 System.out.print(" "+n);
		 }
		
	 }
	 System.out.println();
 } main {
	 int n;
	 int k = new java.util.Scanner(System.in).nextInt();
	 String str;
	 Pattern p = Pattern.compile("3");
	
	 for(n=1;n<=k;n++){
		 str  = String.valueOf(n);
		 Matcher m = p.matcher(str);
		 if(n%3==0||m.find()){
			 System.out.print(" "+n);
		 }
		
	 }
	 System.out.println();
 } int n; n int k = new java.util.Scanner(System.in).nextInt(); k new java.util.Scanner(System.in).nextInt() new java.util.Scanner(System.in).nextInt new java.util.Scanner(System.in) String str; str Pattern p = Pattern.compile("3"); p Pattern.compile("3") Pattern.compile Pattern "3" for(n=1;n<=k;n++){
		 str  = String.valueOf(n);
		 Matcher m = p.matcher(str);
		 if(n%3==0||m.find()){
			 System.out.print(" "+n);
		 }
		
	 } n=1; n=1 n 1 n<=k n k n++ n++ n {
		 str  = String.valueOf(n);
		 Matcher m = p.matcher(str);
		 if(n%3==0||m.find()){
			 System.out.print(" "+n);
		 }
		
	 } {
		 str  = String.valueOf(n);
		 Matcher m = p.matcher(str);
		 if(n%3==0||m.find()){
			 System.out.print(" "+n);
		 }
		
	 } str  = String.valueOf(n) str String.valueOf(n) String.valueOf String n Matcher m = p.matcher(str); m p.matcher(str) p.matcher p str if(n%3==0||m.find()){
			 System.out.print(" "+n);
		 } n%3==0||m.find() n%3==0 n%3 n 3 0 m.find() m.find m {
			 System.out.print(" "+n);
		 } System.out.print(" "+n) System.out.print System.out System System.out " "+n " " n System.out.println() System.out.println System.out System System.out String[] args args public class Main {
 public static void main(String[] args){
	 int n;
	 int k = new java.util.Scanner(System.in).nextInt();
	 String str;
	 Pattern p = Pattern.compile("3");
	
	 for(n=1;n<=k;n++){
		 str  = String.valueOf(n);
		 Matcher m = p.matcher(str);
		 if(n%3==0||m.find()){
			 System.out.print(" "+n);
		 }
		
	 }
	 System.out.println();
 }
} public class Main {
 public static void main(String[] args){
	 int n;
	 int k = new java.util.Scanner(System.in).nextInt();
	 String str;
	 Pattern p = Pattern.compile("3");
	
	 for(n=1;n<=k;n++){
		 str  = String.valueOf(n);
		 Matcher m = p.matcher(str);
		 if(n%3==0||m.find()){
			 System.out.print(" "+n);
		 }
		
	 }
	 System.out.println();
 }
} Main
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
 public static void main(String[] args){
	 int n;
	 int k = new java.util.Scanner(System.in).nextInt();
	 String str;
	 Pattern p = Pattern.compile("3");
	
	 for(n=1;n<=k;n++){
		 str  = String.valueOf(n);
		 Matcher m = p.matcher(str);
		 if(n%3==0||m.find()){
			 System.out.print(" "+n);
		 }
		
	 }
	 System.out.println();
 }
}