import java.util.Scanner;
import java.lang.StringBuilder;
public class Main {
	public static void main(String[] args) throws Exception{
		Scanner sc = new Scanner(System.in);
		StringBuilder bu = new StringBuilder();
		int h=sc.nextInt();
			for(int i=1;i<=h;i++){
				int x=i;
					if(x%3==0){
						bu.append(" ").append(i);
					}else{
						while(x!=0){
							if(x%10==3){
								bu.append(" ").append(i);
								break;
							}else{
								x/=10;
							}
						}
					}
			}
		System.out.println(bu);
	}
} import java.util.Scanner; Scanner java.util import java.lang.StringBuilder; StringBuilder java.lang public class Main {
	public static void main(String[] args) throws Exception{
		Scanner sc = new Scanner(System.in);
		StringBuilder bu = new StringBuilder();
		int h=sc.nextInt();
			for(int i=1;i<=h;i++){
				int x=i;
					if(x%3==0){
						bu.append(" ").append(i);
					}else{
						while(x!=0){
							if(x%10==3){
								bu.append(" ").append(i);
								break;
							}else{
								x/=10;
							}
						}
					}
			}
		System.out.println(bu);
	}
} Main public static void main(String[] args) throws Exception{
		Scanner sc = new Scanner(System.in);
		StringBuilder bu = new StringBuilder();
		int h=sc.nextInt();
			for(int i=1;i<=h;i++){
				int x=i;
					if(x%3==0){
						bu.append(" ").append(i);
					}else{
						while(x!=0){
							if(x%10==3){
								bu.append(" ").append(i);
								break;
							}else{
								x/=10;
							}
						}
					}
			}
		System.out.println(bu);
	} main {
		Scanner sc = new Scanner(System.in);
		StringBuilder bu = new StringBuilder();
		int h=sc.nextInt();
			for(int i=1;i<=h;i++){
				int x=i;
					if(x%3==0){
						bu.append(" ").append(i);
					}else{
						while(x!=0){
							if(x%10==3){
								bu.append(" ").append(i);
								break;
							}else{
								x/=10;
							}
						}
					}
			}
		System.out.println(bu);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) StringBuilder bu = new StringBuilder(); bu new StringBuilder() int h=sc.nextInt(); h sc.nextInt() sc.nextInt sc for(int i=1;i<=h;i++){
				int x=i;
					if(x%3==0){
						bu.append(" ").append(i);
					}else{
						while(x!=0){
							if(x%10==3){
								bu.append(" ").append(i);
								break;
							}else{
								x/=10;
							}
						}
					}
			} int i=1; int i=1; i 1 i<=h i h i++ i++ i {
				int x=i;
					if(x%3==0){
						bu.append(" ").append(i);
					}else{
						while(x!=0){
							if(x%10==3){
								bu.append(" ").append(i);
								break;
							}else{
								x/=10;
							}
						}
					}
			} {
				int x=i;
					if(x%3==0){
						bu.append(" ").append(i);
					}else{
						while(x!=0){
							if(x%10==3){
								bu.append(" ").append(i);
								break;
							}else{
								x/=10;
							}
						}
					}
			} int x=i; x i if(x%3==0){
						bu.append(" ").append(i);
					}else{
						while(x!=0){
							if(x%10==3){
								bu.append(" ").append(i);
								break;
							}else{
								x/=10;
							}
						}
					} x%3==0 x%3 x 3 0 {
						bu.append(" ").append(i);
					} bu.append(" ").append(i) bu.append(" ").append bu.append(" ") bu.append bu " " i {
						while(x!=0){
							if(x%10==3){
								bu.append(" ").append(i);
								break;
							}else{
								x/=10;
							}
						}
					} while(x!=0){
							if(x%10==3){
								bu.append(" ").append(i);
								break;
							}else{
								x/=10;
							}
						} x!=0 x 0 {
							if(x%10==3){
								bu.append(" ").append(i);
								break;
							}else{
								x/=10;
							}
						} if(x%10==3){
								bu.append(" ").append(i);
								break;
							}else{
								x/=10;
							} x%10==3 x%10 x 10 3 {
								bu.append(" ").append(i);
								break;
							} bu.append(" ").append(i) bu.append(" ").append bu.append(" ") bu.append bu " " i break; {
								x/=10;
							} x/=10 x 10 System.out.println(bu) System.out.println System.out System System.out bu String[] args args public class Main {
	public static void main(String[] args) throws Exception{
		Scanner sc = new Scanner(System.in);
		StringBuilder bu = new StringBuilder();
		int h=sc.nextInt();
			for(int i=1;i<=h;i++){
				int x=i;
					if(x%3==0){
						bu.append(" ").append(i);
					}else{
						while(x!=0){
							if(x%10==3){
								bu.append(" ").append(i);
								break;
							}else{
								x/=10;
							}
						}
					}
			}
		System.out.println(bu);
	}
} public class Main {
	public static void main(String[] args) throws Exception{
		Scanner sc = new Scanner(System.in);
		StringBuilder bu = new StringBuilder();
		int h=sc.nextInt();
			for(int i=1;i<=h;i++){
				int x=i;
					if(x%3==0){
						bu.append(" ").append(i);
					}else{
						while(x!=0){
							if(x%10==3){
								bu.append(" ").append(i);
								break;
							}else{
								x/=10;
							}
						}
					}
			}
		System.out.println(bu);
	}
} Main
import java.util.Scanner;
import java.lang.StringBuilder;
public class Main {
	public static void main(String[] args) throws Exception{
		Scanner sc = new Scanner(System.in);
		StringBuilder bu = new StringBuilder();
		int h=sc.nextInt();
			for(int i=1;i<=h;i++){
				int x=i;
					if(x%3==0){
						bu.append(" ").append(i);
					}else{
						while(x!=0){
							if(x%10==3){
								bu.append(" ").append(i);
								break;
							}else{
								x/=10;
							}
						}
					}
			}
		System.out.println(bu);
	}
}