public class Main {
	
	public void run(java.io.InputStream in, java.io.PrintStream out) {
		final java.util.Scanner sc = new java.util.Scanner(in);
		final int n = sc.nextInt();
		
		for (int i = 1; i <= n; ++i) {
			if (i % 3 == 0) {
				out.print(" " + i);
			} else {
				for (int j = i; j > 0; j /= 10) {
					if (j % 10 == 3) {
						out.print(" " + i);
						break ;
					}
				}
			}
		}
		out.println();
		sc.close();
	}

	public static void main(String[] args) {
		(new Main()).run(System.in, System.out);
	}

} public class Main {
	
	public void run(java.io.InputStream in, java.io.PrintStream out) {
		final java.util.Scanner sc = new java.util.Scanner(in);
		final int n = sc.nextInt();
		
		for (int i = 1; i <= n; ++i) {
			if (i % 3 == 0) {
				out.print(" " + i);
			} else {
				for (int j = i; j > 0; j /= 10) {
					if (j % 10 == 3) {
						out.print(" " + i);
						break ;
					}
				}
			}
		}
		out.println();
		sc.close();
	}

	public static void main(String[] args) {
		(new Main()).run(System.in, System.out);
	}

} Main public void run(java.io.InputStream in, java.io.PrintStream out) {
		final java.util.Scanner sc = new java.util.Scanner(in);
		final int n = sc.nextInt();
		
		for (int i = 1; i <= n; ++i) {
			if (i % 3 == 0) {
				out.print(" " + i);
			} else {
				for (int j = i; j > 0; j /= 10) {
					if (j % 10 == 3) {
						out.print(" " + i);
						break ;
					}
				}
			}
		}
		out.println();
		sc.close();
	} run {
		final java.util.Scanner sc = new java.util.Scanner(in);
		final int n = sc.nextInt();
		
		for (int i = 1; i <= n; ++i) {
			if (i % 3 == 0) {
				out.print(" " + i);
			} else {
				for (int j = i; j > 0; j /= 10) {
					if (j % 10 == 3) {
						out.print(" " + i);
						break ;
					}
				}
			}
		}
		out.println();
		sc.close();
	} final java.util.Scanner sc = new java.util.Scanner(in); sc new java.util.Scanner(in) final int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc for (int i = 1; i <= n; ++i) {
			if (i % 3 == 0) {
				out.print(" " + i);
			} else {
				for (int j = i; j > 0; j /= 10) {
					if (j % 10 == 3) {
						out.print(" " + i);
						break ;
					}
				}
			}
		} int i = 1; int i = 1; i 1 i <= n i n ++i ++i i {
			if (i % 3 == 0) {
				out.print(" " + i);
			} else {
				for (int j = i; j > 0; j /= 10) {
					if (j % 10 == 3) {
						out.print(" " + i);
						break ;
					}
				}
			}
		} {
			if (i % 3 == 0) {
				out.print(" " + i);
			} else {
				for (int j = i; j > 0; j /= 10) {
					if (j % 10 == 3) {
						out.print(" " + i);
						break ;
					}
				}
			}
		} if (i % 3 == 0) {
				out.print(" " + i);
			} else {
				for (int j = i; j > 0; j /= 10) {
					if (j % 10 == 3) {
						out.print(" " + i);
						break ;
					}
				}
			} i % 3 == 0 i % 3 i 3 0 {
				out.print(" " + i);
			} out.print(" " + i) out.print out " " + i " " i {
				for (int j = i; j > 0; j /= 10) {
					if (j % 10 == 3) {
						out.print(" " + i);
						break ;
					}
				}
			} for (int j = i; j > 0; j /= 10) {
					if (j % 10 == 3) {
						out.print(" " + i);
						break ;
					}
				} int j = i; int j = i; j i j > 0 j 0 j /= 10 j /= 10 j 10 {
					if (j % 10 == 3) {
						out.print(" " + i);
						break ;
					}
				} {
					if (j % 10 == 3) {
						out.print(" " + i);
						break ;
					}
				} if (j % 10 == 3) {
						out.print(" " + i);
						break ;
					} j % 10 == 3 j % 10 j 10 3 {
						out.print(" " + i);
						break ;
					} out.print(" " + i) out.print out " " + i " " i break ; out.println() out.println out sc.close() sc.close sc java.io.InputStream in in java.io.PrintStream out out public static void main(String[] args) {
		(new Main()).run(System.in, System.out);
	} main {
		(new Main()).run(System.in, System.out);
	} (new Main()).run(System.in, System.out) (new Main()).run (new Main()) System.in System System.in System.out System System.out String[] args args public class Main {
	
	public void run(java.io.InputStream in, java.io.PrintStream out) {
		final java.util.Scanner sc = new java.util.Scanner(in);
		final int n = sc.nextInt();
		
		for (int i = 1; i <= n; ++i) {
			if (i % 3 == 0) {
				out.print(" " + i);
			} else {
				for (int j = i; j > 0; j /= 10) {
					if (j % 10 == 3) {
						out.print(" " + i);
						break ;
					}
				}
			}
		}
		out.println();
		sc.close();
	}

	public static void main(String[] args) {
		(new Main()).run(System.in, System.out);
	}

} public class Main {
	
	public void run(java.io.InputStream in, java.io.PrintStream out) {
		final java.util.Scanner sc = new java.util.Scanner(in);
		final int n = sc.nextInt();
		
		for (int i = 1; i <= n; ++i) {
			if (i % 3 == 0) {
				out.print(" " + i);
			} else {
				for (int j = i; j > 0; j /= 10) {
					if (j % 10 == 3) {
						out.print(" " + i);
						break ;
					}
				}
			}
		}
		out.println();
		sc.close();
	}

	public static void main(String[] args) {
		(new Main()).run(System.in, System.out);
	}

} Main
public class Main {
	
	public void run(java.io.InputStream in, java.io.PrintStream out) {
		final java.util.Scanner sc = new java.util.Scanner(in);
		final int n = sc.nextInt();
		
		for (int i = 1; i <= n; ++i) {
			if (i % 3 == 0) {
				out.print(" " + i);
			} else {
				for (int j = i; j > 0; j /= 10) {
					if (j % 10 == 3) {
						out.print(" " + i);
						break ;
					}
				}
			}
		}
		out.println();
		sc.close();
	}

	public static void main(String[] args) {
		(new Main()).run(System.in, System.out);
	}

}