import java.util.Scanner;

class Main{
    public static void main(String[] args){
        int n;
		Scanner scanner = new Scanner(System.in);
		n = scanner.nextInt();
		
		for(int i = 3; i <= n; i ++){
			String str_i = String.valueOf(i);
			if(i % 3 == 0 || str_i.indexOf("3") != -1){
				System.out.print(" "+i);	
			}
		}
		System.out.println();
    	scanner.close();
    }
} import java.util.Scanner; Scanner java.util class Main{
    public static void main(String[] args){
        int n;
		Scanner scanner = new Scanner(System.in);
		n = scanner.nextInt();
		
		for(int i = 3; i <= n; i ++){
			String str_i = String.valueOf(i);
			if(i % 3 == 0 || str_i.indexOf("3") != -1){
				System.out.print(" "+i);	
			}
		}
		System.out.println();
    	scanner.close();
    }
} Main public static void main(String[] args){
        int n;
		Scanner scanner = new Scanner(System.in);
		n = scanner.nextInt();
		
		for(int i = 3; i <= n; i ++){
			String str_i = String.valueOf(i);
			if(i % 3 == 0 || str_i.indexOf("3") != -1){
				System.out.print(" "+i);	
			}
		}
		System.out.println();
    	scanner.close();
    } main {
        int n;
		Scanner scanner = new Scanner(System.in);
		n = scanner.nextInt();
		
		for(int i = 3; i <= n; i ++){
			String str_i = String.valueOf(i);
			if(i % 3 == 0 || str_i.indexOf("3") != -1){
				System.out.print(" "+i);	
			}
		}
		System.out.println();
    	scanner.close();
    } int n; n Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) n = scanner.nextInt() n scanner.nextInt() scanner.nextInt scanner for(int i = 3; i <= n; i ++){
			String str_i = String.valueOf(i);
			if(i % 3 == 0 || str_i.indexOf("3") != -1){
				System.out.print(" "+i);	
			}
		} int i = 3; int i = 3; i 3 i <= n i n i ++ i ++ i {
			String str_i = String.valueOf(i);
			if(i % 3 == 0 || str_i.indexOf("3") != -1){
				System.out.print(" "+i);	
			}
		} {
			String str_i = String.valueOf(i);
			if(i % 3 == 0 || str_i.indexOf("3") != -1){
				System.out.print(" "+i);	
			}
		} String str_i = String.valueOf(i); str_i String.valueOf(i) String.valueOf String i if(i % 3 == 0 || str_i.indexOf("3") != -1){
				System.out.print(" "+i);	
			} i % 3 == 0 || str_i.indexOf("3") != -1 i % 3 == 0 i % 3 i 3 0 str_i.indexOf("3") != -1 str_i.indexOf("3") str_i.indexOf str_i "3" -1 1 {
				System.out.print(" "+i);	
			} System.out.print(" "+i) System.out.print System.out System System.out " "+i " " i System.out.println() System.out.println System.out System System.out scanner.close() scanner.close scanner String[] args args
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        int n;
		Scanner scanner = new Scanner(System.in);
		n = scanner.nextInt();
		
		for(int i = 3; i <= n; i ++){
			String str_i = String.valueOf(i);
			if(i % 3 == 0 || str_i.indexOf("3") != -1){
				System.out.print(" "+i);	
			}
		}
		System.out.println();
    	scanner.close();
    }
}