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