import java.io.*;
public class Main{
	public static void main(String[] args)throws Exception{
		BufferedReader input=new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb=new StringBuilder();
		String str=input.readLine();
		int n=Integer.parseInt(str);
		int ii=0;
		for(int i=0;i<=n;i++){
			if(!(i==0)){
				if(i%3==0){
					sb.append(" ").append(i);
					}else{
						 ii=i;
						while(!(ii==0)){
							if(ii%10==3){
								sb.append(" ").append(i);
								break;
							}
							ii/=10;
						}
					}
				}		
			}	
		
		System.out.println(sb);
	}
} import java.io.*; io.* java public class Main{
	public static void main(String[] args)throws Exception{
		BufferedReader input=new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb=new StringBuilder();
		String str=input.readLine();
		int n=Integer.parseInt(str);
		int ii=0;
		for(int i=0;i<=n;i++){
			if(!(i==0)){
				if(i%3==0){
					sb.append(" ").append(i);
					}else{
						 ii=i;
						while(!(ii==0)){
							if(ii%10==3){
								sb.append(" ").append(i);
								break;
							}
							ii/=10;
						}
					}
				}		
			}	
		
		System.out.println(sb);
	}
} Main public static void main(String[] args)throws Exception{
		BufferedReader input=new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb=new StringBuilder();
		String str=input.readLine();
		int n=Integer.parseInt(str);
		int ii=0;
		for(int i=0;i<=n;i++){
			if(!(i==0)){
				if(i%3==0){
					sb.append(" ").append(i);
					}else{
						 ii=i;
						while(!(ii==0)){
							if(ii%10==3){
								sb.append(" ").append(i);
								break;
							}
							ii/=10;
						}
					}
				}		
			}	
		
		System.out.println(sb);
	} main {
		BufferedReader input=new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb=new StringBuilder();
		String str=input.readLine();
		int n=Integer.parseInt(str);
		int ii=0;
		for(int i=0;i<=n;i++){
			if(!(i==0)){
				if(i%3==0){
					sb.append(" ").append(i);
					}else{
						 ii=i;
						while(!(ii==0)){
							if(ii%10==3){
								sb.append(" ").append(i);
								break;
							}
							ii/=10;
						}
					}
				}		
			}	
		
		System.out.println(sb);
	} BufferedReader input=new BufferedReader(new InputStreamReader(System.in)); input new BufferedReader(new InputStreamReader(System.in)) StringBuilder sb=new StringBuilder(); sb new StringBuilder() String str=input.readLine(); str input.readLine() input.readLine input int n=Integer.parseInt(str); n Integer.parseInt(str) Integer.parseInt Integer str int ii=0; ii 0 for(int i=0;i<=n;i++){
			if(!(i==0)){
				if(i%3==0){
					sb.append(" ").append(i);
					}else{
						 ii=i;
						while(!(ii==0)){
							if(ii%10==3){
								sb.append(" ").append(i);
								break;
							}
							ii/=10;
						}
					}
				}		
			} int i=0; int i=0; i 0 i<=n i n i++ i++ i {
			if(!(i==0)){
				if(i%3==0){
					sb.append(" ").append(i);
					}else{
						 ii=i;
						while(!(ii==0)){
							if(ii%10==3){
								sb.append(" ").append(i);
								break;
							}
							ii/=10;
						}
					}
				}		
			} {
			if(!(i==0)){
				if(i%3==0){
					sb.append(" ").append(i);
					}else{
						 ii=i;
						while(!(ii==0)){
							if(ii%10==3){
								sb.append(" ").append(i);
								break;
							}
							ii/=10;
						}
					}
				}		
			} if(!(i==0)){
				if(i%3==0){
					sb.append(" ").append(i);
					}else{
						 ii=i;
						while(!(ii==0)){
							if(ii%10==3){
								sb.append(" ").append(i);
								break;
							}
							ii/=10;
						}
					}
				} !(i==0) (i==0) i 0 {
				if(i%3==0){
					sb.append(" ").append(i);
					}else{
						 ii=i;
						while(!(ii==0)){
							if(ii%10==3){
								sb.append(" ").append(i);
								break;
							}
							ii/=10;
						}
					}
				} if(i%3==0){
					sb.append(" ").append(i);
					}else{
						 ii=i;
						while(!(ii==0)){
							if(ii%10==3){
								sb.append(" ").append(i);
								break;
							}
							ii/=10;
						}
					} i%3==0 i%3 i 3 0 {
					sb.append(" ").append(i);
					} sb.append(" ").append(i) sb.append(" ").append sb.append(" ") sb.append sb " " i {
						 ii=i;
						while(!(ii==0)){
							if(ii%10==3){
								sb.append(" ").append(i);
								break;
							}
							ii/=10;
						}
					} ii=i ii i while(!(ii==0)){
							if(ii%10==3){
								sb.append(" ").append(i);
								break;
							}
							ii/=10;
						} !(ii==0) (ii==0) ii 0 {
							if(ii%10==3){
								sb.append(" ").append(i);
								break;
							}
							ii/=10;
						} if(ii%10==3){
								sb.append(" ").append(i);
								break;
							} ii%10==3 ii%10 ii 10 3 {
								sb.append(" ").append(i);
								break;
							} sb.append(" ").append(i) sb.append(" ").append sb.append(" ") sb.append sb " " i break; ii/=10 ii 10 System.out.println(sb) System.out.println System.out System System.out sb String[] args args public class Main{
	public static void main(String[] args)throws Exception{
		BufferedReader input=new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb=new StringBuilder();
		String str=input.readLine();
		int n=Integer.parseInt(str);
		int ii=0;
		for(int i=0;i<=n;i++){
			if(!(i==0)){
				if(i%3==0){
					sb.append(" ").append(i);
					}else{
						 ii=i;
						while(!(ii==0)){
							if(ii%10==3){
								sb.append(" ").append(i);
								break;
							}
							ii/=10;
						}
					}
				}		
			}	
		
		System.out.println(sb);
	}
} public class Main{
	public static void main(String[] args)throws Exception{
		BufferedReader input=new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb=new StringBuilder();
		String str=input.readLine();
		int n=Integer.parseInt(str);
		int ii=0;
		for(int i=0;i<=n;i++){
			if(!(i==0)){
				if(i%3==0){
					sb.append(" ").append(i);
					}else{
						 ii=i;
						while(!(ii==0)){
							if(ii%10==3){
								sb.append(" ").append(i);
								break;
							}
							ii/=10;
						}
					}
				}		
			}	
		
		System.out.println(sb);
	}
} Main
import java.io.*;
public class Main{
	public static void main(String[] args)throws Exception{
		BufferedReader input=new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb=new StringBuilder();
		String str=input.readLine();
		int n=Integer.parseInt(str);
		int ii=0;
		for(int i=0;i<=n;i++){
			if(!(i==0)){
				if(i%3==0){
					sb.append(" ").append(i);
					}else{
						 ii=i;
						while(!(ii==0)){
							if(ii%10==3){
								sb.append(" ").append(i);
								break;
							}
							ii/=10;
						}
					}
				}		
			}	
		
		System.out.println(sb);
	}
}