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