import java.io.*;
import java.lang.*;
import java.util.Scanner;
import java.util.Arrays;
import java.util.ArrayList;

public class Main {
	public static void main(String[] args){
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(isr);
		String buf;
		try {
			while(br.ready()){
				buf = br.readLine();
				Scanner scanner = new Scanner(buf);
				int i, x, n = scanner.nextInt();

				for(i = 1; i <= n; i++){
					x = i;
					if(x % 3 == 0){
						System.out.print(" " + i);
					} else{
						for(;;){
							if(x % 10 == 3){
								System.out.print(" " + i);
								break;
							}
							x /= 10;
							if(x == 0){
								break;
							}
						}
					}
				}
				System.out.print("\n");
			}
		}
		catch(IOException e) {
			System.out.println("Read error.");
			return;
		}
	}
} import java.io.*; io.* java import java.lang.*; lang.* java import java.util.Scanner; Scanner java.util import java.util.Arrays; Arrays java.util import java.util.ArrayList; ArrayList java.util public class Main {
	public static void main(String[] args){
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(isr);
		String buf;
		try {
			while(br.ready()){
				buf = br.readLine();
				Scanner scanner = new Scanner(buf);
				int i, x, n = scanner.nextInt();

				for(i = 1; i <= n; i++){
					x = i;
					if(x % 3 == 0){
						System.out.print(" " + i);
					} else{
						for(;;){
							if(x % 10 == 3){
								System.out.print(" " + i);
								break;
							}
							x /= 10;
							if(x == 0){
								break;
							}
						}
					}
				}
				System.out.print("\n");
			}
		}
		catch(IOException e) {
			System.out.println("Read error.");
			return;
		}
	}
} Main public static void main(String[] args){
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(isr);
		String buf;
		try {
			while(br.ready()){
				buf = br.readLine();
				Scanner scanner = new Scanner(buf);
				int i, x, n = scanner.nextInt();

				for(i = 1; i <= n; i++){
					x = i;
					if(x % 3 == 0){
						System.out.print(" " + i);
					} else{
						for(;;){
							if(x % 10 == 3){
								System.out.print(" " + i);
								break;
							}
							x /= 10;
							if(x == 0){
								break;
							}
						}
					}
				}
				System.out.print("\n");
			}
		}
		catch(IOException e) {
			System.out.println("Read error.");
			return;
		}
	} main {
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(isr);
		String buf;
		try {
			while(br.ready()){
				buf = br.readLine();
				Scanner scanner = new Scanner(buf);
				int i, x, n = scanner.nextInt();

				for(i = 1; i <= n; i++){
					x = i;
					if(x % 3 == 0){
						System.out.print(" " + i);
					} else{
						for(;;){
							if(x % 10 == 3){
								System.out.print(" " + i);
								break;
							}
							x /= 10;
							if(x == 0){
								break;
							}
						}
					}
				}
				System.out.print("\n");
			}
		}
		catch(IOException e) {
			System.out.println("Read error.");
			return;
		}
	} InputStreamReader isr = new InputStreamReader(System.in); isr new InputStreamReader(System.in) BufferedReader br = new BufferedReader(isr); br new BufferedReader(isr) String buf; buf try {
			while(br.ready()){
				buf = br.readLine();
				Scanner scanner = new Scanner(buf);
				int i, x, n = scanner.nextInt();

				for(i = 1; i <= n; i++){
					x = i;
					if(x % 3 == 0){
						System.out.print(" " + i);
					} else{
						for(;;){
							if(x % 10 == 3){
								System.out.print(" " + i);
								break;
							}
							x /= 10;
							if(x == 0){
								break;
							}
						}
					}
				}
				System.out.print("\n");
			}
		}
		catch(IOException e) {
			System.out.println("Read error.");
			return;
		} catch(IOException e) {
			System.out.println("Read error.");
			return;
		} IOException e {
			System.out.println("Read error.");
			return;
		} System.out.println("Read error.") System.out.println System.out System System.out "Read error." return; {
			while(br.ready()){
				buf = br.readLine();
				Scanner scanner = new Scanner(buf);
				int i, x, n = scanner.nextInt();

				for(i = 1; i <= n; i++){
					x = i;
					if(x % 3 == 0){
						System.out.print(" " + i);
					} else{
						for(;;){
							if(x % 10 == 3){
								System.out.print(" " + i);
								break;
							}
							x /= 10;
							if(x == 0){
								break;
							}
						}
					}
				}
				System.out.print("\n");
			}
		} while(br.ready()){
				buf = br.readLine();
				Scanner scanner = new Scanner(buf);
				int i, x, n = scanner.nextInt();

				for(i = 1; i <= n; i++){
					x = i;
					if(x % 3 == 0){
						System.out.print(" " + i);
					} else{
						for(;;){
							if(x % 10 == 3){
								System.out.print(" " + i);
								break;
							}
							x /= 10;
							if(x == 0){
								break;
							}
						}
					}
				}
				System.out.print("\n");
			} br.ready() br.ready br {
				buf = br.readLine();
				Scanner scanner = new Scanner(buf);
				int i, x, n = scanner.nextInt();

				for(i = 1; i <= n; i++){
					x = i;
					if(x % 3 == 0){
						System.out.print(" " + i);
					} else{
						for(;;){
							if(x % 10 == 3){
								System.out.print(" " + i);
								break;
							}
							x /= 10;
							if(x == 0){
								break;
							}
						}
					}
				}
				System.out.print("\n");
			} buf = br.readLine() buf br.readLine() br.readLine br Scanner scanner = new Scanner(buf); scanner new Scanner(buf) int i i x x n = scanner.nextInt(); n scanner.nextInt() scanner.nextInt scanner for(i = 1; i <= n; i++){
					x = i;
					if(x % 3 == 0){
						System.out.print(" " + i);
					} else{
						for(;;){
							if(x % 10 == 3){
								System.out.print(" " + i);
								break;
							}
							x /= 10;
							if(x == 0){
								break;
							}
						}
					}
				} i = 1; i = 1 i 1 i <= n i n i++ i++ i {
					x = i;
					if(x % 3 == 0){
						System.out.print(" " + i);
					} else{
						for(;;){
							if(x % 10 == 3){
								System.out.print(" " + i);
								break;
							}
							x /= 10;
							if(x == 0){
								break;
							}
						}
					}
				} {
					x = i;
					if(x % 3 == 0){
						System.out.print(" " + i);
					} else{
						for(;;){
							if(x % 10 == 3){
								System.out.print(" " + i);
								break;
							}
							x /= 10;
							if(x == 0){
								break;
							}
						}
					}
				} x = i x i if(x % 3 == 0){
						System.out.print(" " + i);
					} else{
						for(;;){
							if(x % 10 == 3){
								System.out.print(" " + i);
								break;
							}
							x /= 10;
							if(x == 0){
								break;
							}
						}
					} x % 3 == 0 x % 3 x 3 0 {
						System.out.print(" " + i);
					} System.out.print(" " + i) System.out.print System.out System System.out " " + i " " i {
						for(;;){
							if(x % 10 == 3){
								System.out.print(" " + i);
								break;
							}
							x /= 10;
							if(x == 0){
								break;
							}
						}
					} for(;;){
							if(x % 10 == 3){
								System.out.print(" " + i);
								break;
							}
							x /= 10;
							if(x == 0){
								break;
							}
						} ; {
							if(x % 10 == 3){
								System.out.print(" " + i);
								break;
							}
							x /= 10;
							if(x == 0){
								break;
							}
						} {
							if(x % 10 == 3){
								System.out.print(" " + i);
								break;
							}
							x /= 10;
							if(x == 0){
								break;
							}
						} if(x % 10 == 3){
								System.out.print(" " + i);
								break;
							} x % 10 == 3 x % 10 x 10 3 {
								System.out.print(" " + i);
								break;
							} System.out.print(" " + i) System.out.print System.out System System.out " " + i " " i break; x /= 10 x 10 if(x == 0){
								break;
							} x == 0 x 0 {
								break;
							} break; System.out.print("\n") System.out.print System.out System System.out "\n" String[] args args public class Main {
	public static void main(String[] args){
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(isr);
		String buf;
		try {
			while(br.ready()){
				buf = br.readLine();
				Scanner scanner = new Scanner(buf);
				int i, x, n = scanner.nextInt();

				for(i = 1; i <= n; i++){
					x = i;
					if(x % 3 == 0){
						System.out.print(" " + i);
					} else{
						for(;;){
							if(x % 10 == 3){
								System.out.print(" " + i);
								break;
							}
							x /= 10;
							if(x == 0){
								break;
							}
						}
					}
				}
				System.out.print("\n");
			}
		}
		catch(IOException e) {
			System.out.println("Read error.");
			return;
		}
	}
} public class Main {
	public static void main(String[] args){
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(isr);
		String buf;
		try {
			while(br.ready()){
				buf = br.readLine();
				Scanner scanner = new Scanner(buf);
				int i, x, n = scanner.nextInt();

				for(i = 1; i <= n; i++){
					x = i;
					if(x % 3 == 0){
						System.out.print(" " + i);
					} else{
						for(;;){
							if(x % 10 == 3){
								System.out.print(" " + i);
								break;
							}
							x /= 10;
							if(x == 0){
								break;
							}
						}
					}
				}
				System.out.print("\n");
			}
		}
		catch(IOException e) {
			System.out.println("Read error.");
			return;
		}
	}
} Main
import java.io.*;
import java.lang.*;
import java.util.Scanner;
import java.util.Arrays;
import java.util.ArrayList;

public class Main {
	public static void main(String[] args){
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(isr);
		String buf;
		try {
			while(br.ready()){
				buf = br.readLine();
				Scanner scanner = new Scanner(buf);
				int i, x, n = scanner.nextInt();

				for(i = 1; i <= n; i++){
					x = i;
					if(x % 3 == 0){
						System.out.print(" " + i);
					} else{
						for(;;){
							if(x % 10 == 3){
								System.out.print(" " + i);
								break;
							}
							x /= 10;
							if(x == 0){
								break;
							}
						}
					}
				}
				System.out.print("\n");
			}
		}
		catch(IOException e) {
			System.out.println("Read error.");
			return;
		}
	}
}