import java.util.Scanner;
class Main {
	int n,i,x;
	public void suzuki(){
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		for(i = 3;i <= n;i++){
			x = i;
			if(x % 3 == 0){
				System.out.print(" ");
				System.out.print(i);
			}else{
				while(x >= 3){
					if(x % 10 == 3){
						System.out.print(" ");
						System.out.print(i);
						x = 0;
					}else{
						x /= 10;
					}
				}
			}
		}
        System.out.println();
	}
	public static void main(String[] args){
		new Main().suzuki();
	}
} import java.util.Scanner; Scanner java.util class Main {
	int n,i,x;
	public void suzuki(){
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		for(i = 3;i <= n;i++){
			x = i;
			if(x % 3 == 0){
				System.out.print(" ");
				System.out.print(i);
			}else{
				while(x >= 3){
					if(x % 10 == 3){
						System.out.print(" ");
						System.out.print(i);
						x = 0;
					}else{
						x /= 10;
					}
				}
			}
		}
        System.out.println();
	}
	public static void main(String[] args){
		new Main().suzuki();
	}
} Main int n n i i x; x public void suzuki(){
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		for(i = 3;i <= n;i++){
			x = i;
			if(x % 3 == 0){
				System.out.print(" ");
				System.out.print(i);
			}else{
				while(x >= 3){
					if(x % 10 == 3){
						System.out.print(" ");
						System.out.print(i);
						x = 0;
					}else{
						x /= 10;
					}
				}
			}
		}
        System.out.println();
	} suzuki {
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		for(i = 3;i <= n;i++){
			x = i;
			if(x % 3 == 0){
				System.out.print(" ");
				System.out.print(i);
			}else{
				while(x >= 3){
					if(x % 10 == 3){
						System.out.print(" ");
						System.out.print(i);
						x = 0;
					}else{
						x /= 10;
					}
				}
			}
		}
        System.out.println();
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) n = sc.nextInt() n sc.nextInt() sc.nextInt sc for(i = 3;i <= n;i++){
			x = i;
			if(x % 3 == 0){
				System.out.print(" ");
				System.out.print(i);
			}else{
				while(x >= 3){
					if(x % 10 == 3){
						System.out.print(" ");
						System.out.print(i);
						x = 0;
					}else{
						x /= 10;
					}
				}
			}
		} i = 3; i = 3 i 3 i <= n i n i++ i++ i {
			x = i;
			if(x % 3 == 0){
				System.out.print(" ");
				System.out.print(i);
			}else{
				while(x >= 3){
					if(x % 10 == 3){
						System.out.print(" ");
						System.out.print(i);
						x = 0;
					}else{
						x /= 10;
					}
				}
			}
		} {
			x = i;
			if(x % 3 == 0){
				System.out.print(" ");
				System.out.print(i);
			}else{
				while(x >= 3){
					if(x % 10 == 3){
						System.out.print(" ");
						System.out.print(i);
						x = 0;
					}else{
						x /= 10;
					}
				}
			}
		} x = i x i if(x % 3 == 0){
				System.out.print(" ");
				System.out.print(i);
			}else{
				while(x >= 3){
					if(x % 10 == 3){
						System.out.print(" ");
						System.out.print(i);
						x = 0;
					}else{
						x /= 10;
					}
				}
			} x % 3 == 0 x % 3 x 3 0 {
				System.out.print(" ");
				System.out.print(i);
			} System.out.print(" ") System.out.print System.out System System.out " " System.out.print(i) System.out.print System.out System System.out i {
				while(x >= 3){
					if(x % 10 == 3){
						System.out.print(" ");
						System.out.print(i);
						x = 0;
					}else{
						x /= 10;
					}
				}
			} while(x >= 3){
					if(x % 10 == 3){
						System.out.print(" ");
						System.out.print(i);
						x = 0;
					}else{
						x /= 10;
					}
				} x >= 3 x 3 {
					if(x % 10 == 3){
						System.out.print(" ");
						System.out.print(i);
						x = 0;
					}else{
						x /= 10;
					}
				} if(x % 10 == 3){
						System.out.print(" ");
						System.out.print(i);
						x = 0;
					}else{
						x /= 10;
					} x % 10 == 3 x % 10 x 10 3 {
						System.out.print(" ");
						System.out.print(i);
						x = 0;
					} System.out.print(" ") System.out.print System.out System System.out " " System.out.print(i) System.out.print System.out System System.out i x = 0 x 0 {
						x /= 10;
					} x /= 10 x 10 System.out.println() System.out.println System.out System System.out public static void main(String[] args){
		new Main().suzuki();
	} main {
		new Main().suzuki();
	} new Main().suzuki() new Main().suzuki new Main() String[] args args
import java.util.Scanner;
class Main {
	int n,i,x;
	public void suzuki(){
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		for(i = 3;i <= n;i++){
			x = i;
			if(x % 3 == 0){
				System.out.print(" ");
				System.out.print(i);
			}else{
				while(x >= 3){
					if(x % 10 == 3){
						System.out.print(" ");
						System.out.print(i);
						x = 0;
					}else{
						x /= 10;
					}
				}
			}
		}
        System.out.println();
	}
	public static void main(String[] args){
		new Main().suzuki();
	}
}