
import java.util.Scanner;

class Main {
    public static void main(String args[]){
		
	//整数nを読み取る
	Scanner sc = new Scanner(System.in);
	String s1 = sc.next();
        int n = Integer.parseInt(s1);
        
        //nが条件（３から１００００）内か確認
        if(3 <= n && n <= 10000){
        	
        	//１からnまで繰り返す
        	for(int i = 1; i <= n; i++){
        		
        		//３の倍数と３とつく数字を表示
        		if(i % 3 == 0){
        			System.out.print(" " + i);
        		}
        		else if(i % 10 == 3){
        			System.out.print(" " + i);
        		}
        		else{
        		    String si = String.valueOf(i);
        		    for(int j = 0; j < si.length() - 1; j++){
        			   char ci = si.charAt(j);
        			   if(ci == '3'){
        				   System.out.print(" " + i);
        				   break;
        			   }
        		    }
        		}
        	}
        	System.out.println("");
        }
    }
} import java.util.Scanner; Scanner java.util class Main {
    public static void main(String args[]){
		
	//整数nを読み取る
	Scanner sc = new Scanner(System.in);
	String s1 = sc.next();
        int n = Integer.parseInt(s1);
        
        //nが条件（３から１００００）内か確認
        if(3 <= n && n <= 10000){
        	
        	//１からnまで繰り返す
        	for(int i = 1; i <= n; i++){
        		
        		//３の倍数と３とつく数字を表示
        		if(i % 3 == 0){
        			System.out.print(" " + i);
        		}
        		else if(i % 10 == 3){
        			System.out.print(" " + i);
        		}
        		else{
        		    String si = String.valueOf(i);
        		    for(int j = 0; j < si.length() - 1; j++){
        			   char ci = si.charAt(j);
        			   if(ci == '3'){
        				   System.out.print(" " + i);
        				   break;
        			   }
        		    }
        		}
        	}
        	System.out.println("");
        }
    }
} Main public static void main(String args[]){
		
	//整数nを読み取る
	Scanner sc = new Scanner(System.in);
	String s1 = sc.next();
        int n = Integer.parseInt(s1);
        
        //nが条件（３から１００００）内か確認
        if(3 <= n && n <= 10000){
        	
        	//１からnまで繰り返す
        	for(int i = 1; i <= n; i++){
        		
        		//３の倍数と３とつく数字を表示
        		if(i % 3 == 0){
        			System.out.print(" " + i);
        		}
        		else if(i % 10 == 3){
        			System.out.print(" " + i);
        		}
        		else{
        		    String si = String.valueOf(i);
        		    for(int j = 0; j < si.length() - 1; j++){
        			   char ci = si.charAt(j);
        			   if(ci == '3'){
        				   System.out.print(" " + i);
        				   break;
        			   }
        		    }
        		}
        	}
        	System.out.println("");
        }
    } main {
		
	//整数nを読み取る
	Scanner sc = new Scanner(System.in);
	String s1 = sc.next();
        int n = Integer.parseInt(s1);
        
        //nが条件（３から１００００）内か確認
        if(3 <= n && n <= 10000){
        	
        	//１からnまで繰り返す
        	for(int i = 1; i <= n; i++){
        		
        		//３の倍数と３とつく数字を表示
        		if(i % 3 == 0){
        			System.out.print(" " + i);
        		}
        		else if(i % 10 == 3){
        			System.out.print(" " + i);
        		}
        		else{
        		    String si = String.valueOf(i);
        		    for(int j = 0; j < si.length() - 1; j++){
        			   char ci = si.charAt(j);
        			   if(ci == '3'){
        				   System.out.print(" " + i);
        				   break;
        			   }
        		    }
        		}
        	}
        	System.out.println("");
        }
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String s1 = sc.next(); s1 sc.next() sc.next sc int n = Integer.parseInt(s1); n Integer.parseInt(s1) Integer.parseInt Integer s1 if(3 <= n && n <= 10000){
        	
        	//１からnまで繰り返す
        	for(int i = 1; i <= n; i++){
        		
        		//３の倍数と３とつく数字を表示
        		if(i % 3 == 0){
        			System.out.print(" " + i);
        		}
        		else if(i % 10 == 3){
        			System.out.print(" " + i);
        		}
        		else{
        		    String si = String.valueOf(i);
        		    for(int j = 0; j < si.length() - 1; j++){
        			   char ci = si.charAt(j);
        			   if(ci == '3'){
        				   System.out.print(" " + i);
        				   break;
        			   }
        		    }
        		}
        	}
        	System.out.println("");
        } 3 <= n && n <= 10000 3 <= n 3 n n <= 10000 n 10000 {
        	
        	//１からnまで繰り返す
        	for(int i = 1; i <= n; i++){
        		
        		//３の倍数と３とつく数字を表示
        		if(i % 3 == 0){
        			System.out.print(" " + i);
        		}
        		else if(i % 10 == 3){
        			System.out.print(" " + i);
        		}
        		else{
        		    String si = String.valueOf(i);
        		    for(int j = 0; j < si.length() - 1; j++){
        			   char ci = si.charAt(j);
        			   if(ci == '3'){
        				   System.out.print(" " + i);
        				   break;
        			   }
        		    }
        		}
        	}
        	System.out.println("");
        } for(int i = 1; i <= n; i++){
        		
        		//３の倍数と３とつく数字を表示
        		if(i % 3 == 0){
        			System.out.print(" " + i);
        		}
        		else if(i % 10 == 3){
        			System.out.print(" " + i);
        		}
        		else{
        		    String si = String.valueOf(i);
        		    for(int j = 0; j < si.length() - 1; j++){
        			   char ci = si.charAt(j);
        			   if(ci == '3'){
        				   System.out.print(" " + i);
        				   break;
        			   }
        		    }
        		}
        	} int i = 1; int i = 1; i 1 i <= n i n i++ i++ i {
        		
        		//３の倍数と３とつく数字を表示
        		if(i % 3 == 0){
        			System.out.print(" " + i);
        		}
        		else if(i % 10 == 3){
        			System.out.print(" " + i);
        		}
        		else{
        		    String si = String.valueOf(i);
        		    for(int j = 0; j < si.length() - 1; j++){
        			   char ci = si.charAt(j);
        			   if(ci == '3'){
        				   System.out.print(" " + i);
        				   break;
        			   }
        		    }
        		}
        	} {
        		
        		//３の倍数と３とつく数字を表示
        		if(i % 3 == 0){
        			System.out.print(" " + i);
        		}
        		else if(i % 10 == 3){
        			System.out.print(" " + i);
        		}
        		else{
        		    String si = String.valueOf(i);
        		    for(int j = 0; j < si.length() - 1; j++){
        			   char ci = si.charAt(j);
        			   if(ci == '3'){
        				   System.out.print(" " + i);
        				   break;
        			   }
        		    }
        		}
        	} if(i % 3 == 0){
        			System.out.print(" " + i);
        		}
        		else if(i % 10 == 3){
        			System.out.print(" " + i);
        		}
        		else{
        		    String si = String.valueOf(i);
        		    for(int j = 0; j < si.length() - 1; j++){
        			   char ci = si.charAt(j);
        			   if(ci == '3'){
        				   System.out.print(" " + i);
        				   break;
        			   }
        		    }
        		} 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 if(i % 10 == 3){
        			System.out.print(" " + i);
        		}
        		else{
        		    String si = String.valueOf(i);
        		    for(int j = 0; j < si.length() - 1; j++){
        			   char ci = si.charAt(j);
        			   if(ci == '3'){
        				   System.out.print(" " + i);
        				   break;
        			   }
        		    }
        		} i % 10 == 3 i % 10 i 10 3 {
        			System.out.print(" " + i);
        		} System.out.print(" " + i) System.out.print System.out System System.out " " + i " " i {
        		    String si = String.valueOf(i);
        		    for(int j = 0; j < si.length() - 1; j++){
        			   char ci = si.charAt(j);
        			   if(ci == '3'){
        				   System.out.print(" " + i);
        				   break;
        			   }
        		    }
        		} String si = String.valueOf(i); si String.valueOf(i) String.valueOf String i for(int j = 0; j < si.length() - 1; j++){
        			   char ci = si.charAt(j);
        			   if(ci == '3'){
        				   System.out.print(" " + i);
        				   break;
        			   }
        		    } int j = 0; int j = 0; j 0 j < si.length() - 1 j si.length() - 1 si.length() si.length si 1 j++ j++ j {
        			   char ci = si.charAt(j);
        			   if(ci == '3'){
        				   System.out.print(" " + i);
        				   break;
        			   }
        		    } {
        			   char ci = si.charAt(j);
        			   if(ci == '3'){
        				   System.out.print(" " + i);
        				   break;
        			   }
        		    } char ci = si.charAt(j); ci si.charAt(j) si.charAt si j if(ci == '3'){
        				   System.out.print(" " + i);
        				   break;
        			   } ci == '3' ci '3' {
        				   System.out.print(" " + i);
        				   break;
        			   } System.out.print(" " + i) System.out.print System.out System System.out " " + i " " i break; 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[]){
		
	//整数nを読み取る
	Scanner sc = new Scanner(System.in);
	String s1 = sc.next();
        int n = Integer.parseInt(s1);
        
        //nが条件（３から１００００）内か確認
        if(3 <= n && n <= 10000){
        	
        	//１からnまで繰り返す
        	for(int i = 1; i <= n; i++){
        		
        		//３の倍数と３とつく数字を表示
        		if(i % 3 == 0){
        			System.out.print(" " + i);
        		}
        		else if(i % 10 == 3){
        			System.out.print(" " + i);
        		}
        		else{
        		    String si = String.valueOf(i);
        		    for(int j = 0; j < si.length() - 1; j++){
        			   char ci = si.charAt(j);
        			   if(ci == '3'){
        				   System.out.print(" " + i);
        				   break;
        			   }
        		    }
        		}
        	}
        	System.out.println("");
        }
    }
}