import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
	public static void main(String[] args) throws IOException{
		int num;
		String[] str;

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder builder = new StringBuilder();

		str = br.readLine().split(" ");
		num = Integer.parseInt(str[0]);

		for(int i = 1; i <= num; i++){
			if(i % 3 == 0){
				builder.append(" " + i);
			}else if(i % 10 == 3){
				builder.append(" " + i);
			}else{
				int j = i;
				while(true){
					if(j % 10 == 3){
						builder.append(" " + i);
						break;
					}

					if(j >= 10){
						j /= 10;
					}else{
						break;
					}
				}
			}
		}
		System.out.println(builder);
		br.close();
	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {
	public static void main(String[] args) throws IOException{
		int num;
		String[] str;

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder builder = new StringBuilder();

		str = br.readLine().split(" ");
		num = Integer.parseInt(str[0]);

		for(int i = 1; i <= num; i++){
			if(i % 3 == 0){
				builder.append(" " + i);
			}else if(i % 10 == 3){
				builder.append(" " + i);
			}else{
				int j = i;
				while(true){
					if(j % 10 == 3){
						builder.append(" " + i);
						break;
					}

					if(j >= 10){
						j /= 10;
					}else{
						break;
					}
				}
			}
		}
		System.out.println(builder);
		br.close();
	}
} Main public static void main(String[] args) throws IOException{
		int num;
		String[] str;

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder builder = new StringBuilder();

		str = br.readLine().split(" ");
		num = Integer.parseInt(str[0]);

		for(int i = 1; i <= num; i++){
			if(i % 3 == 0){
				builder.append(" " + i);
			}else if(i % 10 == 3){
				builder.append(" " + i);
			}else{
				int j = i;
				while(true){
					if(j % 10 == 3){
						builder.append(" " + i);
						break;
					}

					if(j >= 10){
						j /= 10;
					}else{
						break;
					}
				}
			}
		}
		System.out.println(builder);
		br.close();
	} main {
		int num;
		String[] str;

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder builder = new StringBuilder();

		str = br.readLine().split(" ");
		num = Integer.parseInt(str[0]);

		for(int i = 1; i <= num; i++){
			if(i % 3 == 0){
				builder.append(" " + i);
			}else if(i % 10 == 3){
				builder.append(" " + i);
			}else{
				int j = i;
				while(true){
					if(j % 10 == 3){
						builder.append(" " + i);
						break;
					}

					if(j >= 10){
						j /= 10;
					}else{
						break;
					}
				}
			}
		}
		System.out.println(builder);
		br.close();
	} int num; num String[] str; str BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) StringBuilder builder = new StringBuilder(); builder new StringBuilder() str = br.readLine().split(" ") str br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " num = Integer.parseInt(str[0]) num Integer.parseInt(str[0]) Integer.parseInt Integer str[0] str 0 for(int i = 1; i <= num; i++){
			if(i % 3 == 0){
				builder.append(" " + i);
			}else if(i % 10 == 3){
				builder.append(" " + i);
			}else{
				int j = i;
				while(true){
					if(j % 10 == 3){
						builder.append(" " + i);
						break;
					}

					if(j >= 10){
						j /= 10;
					}else{
						break;
					}
				}
			}
		} int i = 1; int i = 1; i 1 i <= num i num i++ i++ i {
			if(i % 3 == 0){
				builder.append(" " + i);
			}else if(i % 10 == 3){
				builder.append(" " + i);
			}else{
				int j = i;
				while(true){
					if(j % 10 == 3){
						builder.append(" " + i);
						break;
					}

					if(j >= 10){
						j /= 10;
					}else{
						break;
					}
				}
			}
		} {
			if(i % 3 == 0){
				builder.append(" " + i);
			}else if(i % 10 == 3){
				builder.append(" " + i);
			}else{
				int j = i;
				while(true){
					if(j % 10 == 3){
						builder.append(" " + i);
						break;
					}

					if(j >= 10){
						j /= 10;
					}else{
						break;
					}
				}
			}
		} if(i % 3 == 0){
				builder.append(" " + i);
			}else if(i % 10 == 3){
				builder.append(" " + i);
			}else{
				int j = i;
				while(true){
					if(j % 10 == 3){
						builder.append(" " + i);
						break;
					}

					if(j >= 10){
						j /= 10;
					}else{
						break;
					}
				}
			} i % 3 == 0 i % 3 i 3 0 {
				builder.append(" " + i);
			} builder.append(" " + i) builder.append builder " " + i " " i if(i % 10 == 3){
				builder.append(" " + i);
			}else{
				int j = i;
				while(true){
					if(j % 10 == 3){
						builder.append(" " + i);
						break;
					}

					if(j >= 10){
						j /= 10;
					}else{
						break;
					}
				}
			} i % 10 == 3 i % 10 i 10 3 {
				builder.append(" " + i);
			} builder.append(" " + i) builder.append builder " " + i " " i {
				int j = i;
				while(true){
					if(j % 10 == 3){
						builder.append(" " + i);
						break;
					}

					if(j >= 10){
						j /= 10;
					}else{
						break;
					}
				}
			} int j = i; j i while(true){
					if(j % 10 == 3){
						builder.append(" " + i);
						break;
					}

					if(j >= 10){
						j /= 10;
					}else{
						break;
					}
				} true {
					if(j % 10 == 3){
						builder.append(" " + i);
						break;
					}

					if(j >= 10){
						j /= 10;
					}else{
						break;
					}
				} if(j % 10 == 3){
						builder.append(" " + i);
						break;
					} j % 10 == 3 j % 10 j 10 3 {
						builder.append(" " + i);
						break;
					} builder.append(" " + i) builder.append builder " " + i " " i break; if(j >= 10){
						j /= 10;
					}else{
						break;
					} j >= 10 j 10 {
						j /= 10;
					} j /= 10 j 10 {
						break;
					} break; System.out.println(builder) System.out.println System.out System System.out builder br.close() br.close br String[] args args public class Main {
	public static void main(String[] args) throws IOException{
		int num;
		String[] str;

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder builder = new StringBuilder();

		str = br.readLine().split(" ");
		num = Integer.parseInt(str[0]);

		for(int i = 1; i <= num; i++){
			if(i % 3 == 0){
				builder.append(" " + i);
			}else if(i % 10 == 3){
				builder.append(" " + i);
			}else{
				int j = i;
				while(true){
					if(j % 10 == 3){
						builder.append(" " + i);
						break;
					}

					if(j >= 10){
						j /= 10;
					}else{
						break;
					}
				}
			}
		}
		System.out.println(builder);
		br.close();
	}
} public class Main {
	public static void main(String[] args) throws IOException{
		int num;
		String[] str;

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder builder = new StringBuilder();

		str = br.readLine().split(" ");
		num = Integer.parseInt(str[0]);

		for(int i = 1; i <= num; i++){
			if(i % 3 == 0){
				builder.append(" " + i);
			}else if(i % 10 == 3){
				builder.append(" " + i);
			}else{
				int j = i;
				while(true){
					if(j % 10 == 3){
						builder.append(" " + i);
						break;
					}

					if(j >= 10){
						j /= 10;
					}else{
						break;
					}
				}
			}
		}
		System.out.println(builder);
		br.close();
	}
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
	public static void main(String[] args) throws IOException{
		int num;
		String[] str;

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder builder = new StringBuilder();

		str = br.readLine().split(" ");
		num = Integer.parseInt(str[0]);

		for(int i = 1; i <= num; i++){
			if(i % 3 == 0){
				builder.append(" " + i);
			}else if(i % 10 == 3){
				builder.append(" " + i);
			}else{
				int j = i;
				while(true){
					if(j % 10 == 3){
						builder.append(" " + i);
						break;
					}

					if(j >= 10){
						j /= 10;
					}else{
						break;
					}
				}
			}
		}
		System.out.println(builder);
		br.close();
	}
}