import java.io.*;
public class Main{
	public static void main(String[] args){
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		String line;
		int n = -1;
		int i = 1;
		int x;
		try{
			line = reader.readLine();
			n = Integer.parseInt(line);
			while(true){
				x = i;
				if(x % 3 == 0){
					System.out.print(" "+i);
				}else{
					while(true){
						if(x % 10 == 3){
							System.out.print(" "+i);
							break;
						}else{
							x /= 10;
							if(x != 0){
								continue;
							}else{
								break;
							}
						}
					}
				}
				if(++i <= n){
					continue;
				}else{
					break;
				}
			}
			System.out.print("\n");
		}catch(IOException e){
			System.out.println(e);
		}
		
	}
} import java.io.*; io.* java public class Main{
	public static void main(String[] args){
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		String line;
		int n = -1;
		int i = 1;
		int x;
		try{
			line = reader.readLine();
			n = Integer.parseInt(line);
			while(true){
				x = i;
				if(x % 3 == 0){
					System.out.print(" "+i);
				}else{
					while(true){
						if(x % 10 == 3){
							System.out.print(" "+i);
							break;
						}else{
							x /= 10;
							if(x != 0){
								continue;
							}else{
								break;
							}
						}
					}
				}
				if(++i <= n){
					continue;
				}else{
					break;
				}
			}
			System.out.print("\n");
		}catch(IOException e){
			System.out.println(e);
		}
		
	}
} Main public static void main(String[] args){
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		String line;
		int n = -1;
		int i = 1;
		int x;
		try{
			line = reader.readLine();
			n = Integer.parseInt(line);
			while(true){
				x = i;
				if(x % 3 == 0){
					System.out.print(" "+i);
				}else{
					while(true){
						if(x % 10 == 3){
							System.out.print(" "+i);
							break;
						}else{
							x /= 10;
							if(x != 0){
								continue;
							}else{
								break;
							}
						}
					}
				}
				if(++i <= n){
					continue;
				}else{
					break;
				}
			}
			System.out.print("\n");
		}catch(IOException e){
			System.out.println(e);
		}
		
	} main {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		String line;
		int n = -1;
		int i = 1;
		int x;
		try{
			line = reader.readLine();
			n = Integer.parseInt(line);
			while(true){
				x = i;
				if(x % 3 == 0){
					System.out.print(" "+i);
				}else{
					while(true){
						if(x % 10 == 3){
							System.out.print(" "+i);
							break;
						}else{
							x /= 10;
							if(x != 0){
								continue;
							}else{
								break;
							}
						}
					}
				}
				if(++i <= n){
					continue;
				}else{
					break;
				}
			}
			System.out.print("\n");
		}catch(IOException e){
			System.out.println(e);
		}
		
	} BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); reader new BufferedReader(new InputStreamReader(System.in)) String line; line int n = -1; n -1 1 int i = 1; i 1 int x; x try{
			line = reader.readLine();
			n = Integer.parseInt(line);
			while(true){
				x = i;
				if(x % 3 == 0){
					System.out.print(" "+i);
				}else{
					while(true){
						if(x % 10 == 3){
							System.out.print(" "+i);
							break;
						}else{
							x /= 10;
							if(x != 0){
								continue;
							}else{
								break;
							}
						}
					}
				}
				if(++i <= n){
					continue;
				}else{
					break;
				}
			}
			System.out.print("\n");
		}catch(IOException e){
			System.out.println(e);
		} catch(IOException e){
			System.out.println(e);
		} IOException e {
			System.out.println(e);
		} System.out.println(e) System.out.println System.out System System.out e {
			line = reader.readLine();
			n = Integer.parseInt(line);
			while(true){
				x = i;
				if(x % 3 == 0){
					System.out.print(" "+i);
				}else{
					while(true){
						if(x % 10 == 3){
							System.out.print(" "+i);
							break;
						}else{
							x /= 10;
							if(x != 0){
								continue;
							}else{
								break;
							}
						}
					}
				}
				if(++i <= n){
					continue;
				}else{
					break;
				}
			}
			System.out.print("\n");
		} line = reader.readLine() line reader.readLine() reader.readLine reader n = Integer.parseInt(line) n Integer.parseInt(line) Integer.parseInt Integer line while(true){
				x = i;
				if(x % 3 == 0){
					System.out.print(" "+i);
				}else{
					while(true){
						if(x % 10 == 3){
							System.out.print(" "+i);
							break;
						}else{
							x /= 10;
							if(x != 0){
								continue;
							}else{
								break;
							}
						}
					}
				}
				if(++i <= n){
					continue;
				}else{
					break;
				}
			} true {
				x = i;
				if(x % 3 == 0){
					System.out.print(" "+i);
				}else{
					while(true){
						if(x % 10 == 3){
							System.out.print(" "+i);
							break;
						}else{
							x /= 10;
							if(x != 0){
								continue;
							}else{
								break;
							}
						}
					}
				}
				if(++i <= n){
					continue;
				}else{
					break;
				}
			} x = i x i if(x % 3 == 0){
					System.out.print(" "+i);
				}else{
					while(true){
						if(x % 10 == 3){
							System.out.print(" "+i);
							break;
						}else{
							x /= 10;
							if(x != 0){
								continue;
							}else{
								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 {
					while(true){
						if(x % 10 == 3){
							System.out.print(" "+i);
							break;
						}else{
							x /= 10;
							if(x != 0){
								continue;
							}else{
								break;
							}
						}
					}
				} while(true){
						if(x % 10 == 3){
							System.out.print(" "+i);
							break;
						}else{
							x /= 10;
							if(x != 0){
								continue;
							}else{
								break;
							}
						}
					} true {
						if(x % 10 == 3){
							System.out.print(" "+i);
							break;
						}else{
							x /= 10;
							if(x != 0){
								continue;
							}else{
								break;
							}
						}
					} if(x % 10 == 3){
							System.out.print(" "+i);
							break;
						}else{
							x /= 10;
							if(x != 0){
								continue;
							}else{
								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;
							if(x != 0){
								continue;
							}else{
								break;
							}
						} x /= 10 x 10 if(x != 0){
								continue;
							}else{
								break;
							} x != 0 x 0 {
								continue;
							} continue; {
								break;
							} break; if(++i <= n){
					continue;
				}else{
					break;
				} ++i <= n ++i i n {
					continue;
				} continue; {
					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){
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		String line;
		int n = -1;
		int i = 1;
		int x;
		try{
			line = reader.readLine();
			n = Integer.parseInt(line);
			while(true){
				x = i;
				if(x % 3 == 0){
					System.out.print(" "+i);
				}else{
					while(true){
						if(x % 10 == 3){
							System.out.print(" "+i);
							break;
						}else{
							x /= 10;
							if(x != 0){
								continue;
							}else{
								break;
							}
						}
					}
				}
				if(++i <= n){
					continue;
				}else{
					break;
				}
			}
			System.out.print("\n");
		}catch(IOException e){
			System.out.println(e);
		}
		
	}
} public class Main{
	public static void main(String[] args){
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		String line;
		int n = -1;
		int i = 1;
		int x;
		try{
			line = reader.readLine();
			n = Integer.parseInt(line);
			while(true){
				x = i;
				if(x % 3 == 0){
					System.out.print(" "+i);
				}else{
					while(true){
						if(x % 10 == 3){
							System.out.print(" "+i);
							break;
						}else{
							x /= 10;
							if(x != 0){
								continue;
							}else{
								break;
							}
						}
					}
				}
				if(++i <= n){
					continue;
				}else{
					break;
				}
			}
			System.out.print("\n");
		}catch(IOException e){
			System.out.println(e);
		}
		
	}
} Main
import java.io.*;
public class Main{
	public static void main(String[] args){
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		String line;
		int n = -1;
		int i = 1;
		int x;
		try{
			line = reader.readLine();
			n = Integer.parseInt(line);
			while(true){
				x = i;
				if(x % 3 == 0){
					System.out.print(" "+i);
				}else{
					while(true){
						if(x % 10 == 3){
							System.out.print(" "+i);
							break;
						}else{
							x /= 10;
							if(x != 0){
								continue;
							}else{
								break;
							}
						}
					}
				}
				if(++i <= n){
					continue;
				}else{
					break;
				}
			}
			System.out.print("\n");
		}catch(IOException e){
			System.out.println(e);
		}
		
	}
}