import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		String buffer;
		try {
			while ((buffer = reader.readLine())  != null) {
				int n = Integer.valueOf(buffer.substring(0, buffer.indexOf(" ") == -1 ? buffer.length() : buffer.indexOf(" ")));

				for (int i = 1; i <= n; i++) {
					int x = i;
					if (x % 3 == 0) {
						System.out.print(" " + i);
					}
					else {
						if (x % 10 == 3) {
							System.out.print(" " + i);
						}
						else {
							x /= 10;
							if (x % 10 == 3) {
								System.out.print(" " + i);
							}
							else {
								x /= 10;
								if (x % 10 == 3) {
									System.out.print(" " + i);
								}
								else {
									x /= 10;
									if (x % 10 == 3) {
										System.out.print(" " + i);
									}
									else {
										x /= 10;
										if (x % 10 == 3) {
											System.out.print(" " + i);
										}
										else {
											x /= 10;
											if (x % 10 == 3) {
												System.out.print(" " + i);
											}
										}
									}
								}
							}
						}
					}
				}
				System.out.println();
			}
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {

	public static void main(String[] args) {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		String buffer;
		try {
			while ((buffer = reader.readLine())  != null) {
				int n = Integer.valueOf(buffer.substring(0, buffer.indexOf(" ") == -1 ? buffer.length() : buffer.indexOf(" ")));

				for (int i = 1; i <= n; i++) {
					int x = i;
					if (x % 3 == 0) {
						System.out.print(" " + i);
					}
					else {
						if (x % 10 == 3) {
							System.out.print(" " + i);
						}
						else {
							x /= 10;
							if (x % 10 == 3) {
								System.out.print(" " + i);
							}
							else {
								x /= 10;
								if (x % 10 == 3) {
									System.out.print(" " + i);
								}
								else {
									x /= 10;
									if (x % 10 == 3) {
										System.out.print(" " + i);
									}
									else {
										x /= 10;
										if (x % 10 == 3) {
											System.out.print(" " + i);
										}
										else {
											x /= 10;
											if (x % 10 == 3) {
												System.out.print(" " + i);
											}
										}
									}
								}
							}
						}
					}
				}
				System.out.println();
			}
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}
} Main public static void main(String[] args) {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		String buffer;
		try {
			while ((buffer = reader.readLine())  != null) {
				int n = Integer.valueOf(buffer.substring(0, buffer.indexOf(" ") == -1 ? buffer.length() : buffer.indexOf(" ")));

				for (int i = 1; i <= n; i++) {
					int x = i;
					if (x % 3 == 0) {
						System.out.print(" " + i);
					}
					else {
						if (x % 10 == 3) {
							System.out.print(" " + i);
						}
						else {
							x /= 10;
							if (x % 10 == 3) {
								System.out.print(" " + i);
							}
							else {
								x /= 10;
								if (x % 10 == 3) {
									System.out.print(" " + i);
								}
								else {
									x /= 10;
									if (x % 10 == 3) {
										System.out.print(" " + i);
									}
									else {
										x /= 10;
										if (x % 10 == 3) {
											System.out.print(" " + i);
										}
										else {
											x /= 10;
											if (x % 10 == 3) {
												System.out.print(" " + i);
											}
										}
									}
								}
							}
						}
					}
				}
				System.out.println();
			}
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	} main {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		String buffer;
		try {
			while ((buffer = reader.readLine())  != null) {
				int n = Integer.valueOf(buffer.substring(0, buffer.indexOf(" ") == -1 ? buffer.length() : buffer.indexOf(" ")));

				for (int i = 1; i <= n; i++) {
					int x = i;
					if (x % 3 == 0) {
						System.out.print(" " + i);
					}
					else {
						if (x % 10 == 3) {
							System.out.print(" " + i);
						}
						else {
							x /= 10;
							if (x % 10 == 3) {
								System.out.print(" " + i);
							}
							else {
								x /= 10;
								if (x % 10 == 3) {
									System.out.print(" " + i);
								}
								else {
									x /= 10;
									if (x % 10 == 3) {
										System.out.print(" " + i);
									}
									else {
										x /= 10;
										if (x % 10 == 3) {
											System.out.print(" " + i);
										}
										else {
											x /= 10;
											if (x % 10 == 3) {
												System.out.print(" " + i);
											}
										}
									}
								}
							}
						}
					}
				}
				System.out.println();
			}
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	} BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); reader new BufferedReader(new InputStreamReader(System.in)) String buffer; buffer try {
			while ((buffer = reader.readLine())  != null) {
				int n = Integer.valueOf(buffer.substring(0, buffer.indexOf(" ") == -1 ? buffer.length() : buffer.indexOf(" ")));

				for (int i = 1; i <= n; i++) {
					int x = i;
					if (x % 3 == 0) {
						System.out.print(" " + i);
					}
					else {
						if (x % 10 == 3) {
							System.out.print(" " + i);
						}
						else {
							x /= 10;
							if (x % 10 == 3) {
								System.out.print(" " + i);
							}
							else {
								x /= 10;
								if (x % 10 == 3) {
									System.out.print(" " + i);
								}
								else {
									x /= 10;
									if (x % 10 == 3) {
										System.out.print(" " + i);
									}
									else {
										x /= 10;
										if (x % 10 == 3) {
											System.out.print(" " + i);
										}
										else {
											x /= 10;
											if (x % 10 == 3) {
												System.out.print(" " + i);
											}
										}
									}
								}
							}
						}
					}
				}
				System.out.println();
			}
		} catch (Exception ex) {
			ex.printStackTrace();
		} catch (Exception ex) {
			ex.printStackTrace();
		} Exception ex {
			ex.printStackTrace();
		} ex.printStackTrace() ex.printStackTrace ex {
			while ((buffer = reader.readLine())  != null) {
				int n = Integer.valueOf(buffer.substring(0, buffer.indexOf(" ") == -1 ? buffer.length() : buffer.indexOf(" ")));

				for (int i = 1; i <= n; i++) {
					int x = i;
					if (x % 3 == 0) {
						System.out.print(" " + i);
					}
					else {
						if (x % 10 == 3) {
							System.out.print(" " + i);
						}
						else {
							x /= 10;
							if (x % 10 == 3) {
								System.out.print(" " + i);
							}
							else {
								x /= 10;
								if (x % 10 == 3) {
									System.out.print(" " + i);
								}
								else {
									x /= 10;
									if (x % 10 == 3) {
										System.out.print(" " + i);
									}
									else {
										x /= 10;
										if (x % 10 == 3) {
											System.out.print(" " + i);
										}
										else {
											x /= 10;
											if (x % 10 == 3) {
												System.out.print(" " + i);
											}
										}
									}
								}
							}
						}
					}
				}
				System.out.println();
			}
		} while ((buffer = reader.readLine())  != null) {
				int n = Integer.valueOf(buffer.substring(0, buffer.indexOf(" ") == -1 ? buffer.length() : buffer.indexOf(" ")));

				for (int i = 1; i <= n; i++) {
					int x = i;
					if (x % 3 == 0) {
						System.out.print(" " + i);
					}
					else {
						if (x % 10 == 3) {
							System.out.print(" " + i);
						}
						else {
							x /= 10;
							if (x % 10 == 3) {
								System.out.print(" " + i);
							}
							else {
								x /= 10;
								if (x % 10 == 3) {
									System.out.print(" " + i);
								}
								else {
									x /= 10;
									if (x % 10 == 3) {
										System.out.print(" " + i);
									}
									else {
										x /= 10;
										if (x % 10 == 3) {
											System.out.print(" " + i);
										}
										else {
											x /= 10;
											if (x % 10 == 3) {
												System.out.print(" " + i);
											}
										}
									}
								}
							}
						}
					}
				}
				System.out.println();
			} (buffer = reader.readLine())  != null (buffer = reader.readLine()) buffer reader.readLine() reader.readLine reader null {
				int n = Integer.valueOf(buffer.substring(0, buffer.indexOf(" ") == -1 ? buffer.length() : buffer.indexOf(" ")));

				for (int i = 1; i <= n; i++) {
					int x = i;
					if (x % 3 == 0) {
						System.out.print(" " + i);
					}
					else {
						if (x % 10 == 3) {
							System.out.print(" " + i);
						}
						else {
							x /= 10;
							if (x % 10 == 3) {
								System.out.print(" " + i);
							}
							else {
								x /= 10;
								if (x % 10 == 3) {
									System.out.print(" " + i);
								}
								else {
									x /= 10;
									if (x % 10 == 3) {
										System.out.print(" " + i);
									}
									else {
										x /= 10;
										if (x % 10 == 3) {
											System.out.print(" " + i);
										}
										else {
											x /= 10;
											if (x % 10 == 3) {
												System.out.print(" " + i);
											}
										}
									}
								}
							}
						}
					}
				}
				System.out.println();
			} int n = Integer.valueOf(buffer.substring(0, buffer.indexOf(" ") == -1 ? buffer.length() : buffer.indexOf(" "))); n Integer.valueOf(buffer.substring(0, buffer.indexOf(" ") == -1 ? buffer.length() : buffer.indexOf(" "))) Integer.valueOf Integer buffer.substring(0, buffer.indexOf(" ") == -1 ? buffer.length() : buffer.indexOf(" ")) buffer.substring buffer 0 buffer.indexOf(" ") == -1 ? buffer.length() : buffer.indexOf(" ") buffer.indexOf(" ") == -1 buffer.indexOf(" ") buffer.indexOf buffer " " -1 1 buffer.length() buffer.length buffer buffer.indexOf(" ") buffer.indexOf buffer " " for (int i = 1; i <= n; i++) {
					int x = i;
					if (x % 3 == 0) {
						System.out.print(" " + i);
					}
					else {
						if (x % 10 == 3) {
							System.out.print(" " + i);
						}
						else {
							x /= 10;
							if (x % 10 == 3) {
								System.out.print(" " + i);
							}
							else {
								x /= 10;
								if (x % 10 == 3) {
									System.out.print(" " + i);
								}
								else {
									x /= 10;
									if (x % 10 == 3) {
										System.out.print(" " + i);
									}
									else {
										x /= 10;
										if (x % 10 == 3) {
											System.out.print(" " + i);
										}
										else {
											x /= 10;
											if (x % 10 == 3) {
												System.out.print(" " + i);
											}
										}
									}
								}
							}
						}
					}
				} int i = 1; int i = 1; i 1 i <= n i n i++ i++ i {
					int x = i;
					if (x % 3 == 0) {
						System.out.print(" " + i);
					}
					else {
						if (x % 10 == 3) {
							System.out.print(" " + i);
						}
						else {
							x /= 10;
							if (x % 10 == 3) {
								System.out.print(" " + i);
							}
							else {
								x /= 10;
								if (x % 10 == 3) {
									System.out.print(" " + i);
								}
								else {
									x /= 10;
									if (x % 10 == 3) {
										System.out.print(" " + i);
									}
									else {
										x /= 10;
										if (x % 10 == 3) {
											System.out.print(" " + i);
										}
										else {
											x /= 10;
											if (x % 10 == 3) {
												System.out.print(" " + i);
											}
										}
									}
								}
							}
						}
					}
				} {
					int x = i;
					if (x % 3 == 0) {
						System.out.print(" " + i);
					}
					else {
						if (x % 10 == 3) {
							System.out.print(" " + i);
						}
						else {
							x /= 10;
							if (x % 10 == 3) {
								System.out.print(" " + i);
							}
							else {
								x /= 10;
								if (x % 10 == 3) {
									System.out.print(" " + i);
								}
								else {
									x /= 10;
									if (x % 10 == 3) {
										System.out.print(" " + i);
									}
									else {
										x /= 10;
										if (x % 10 == 3) {
											System.out.print(" " + i);
										}
										else {
											x /= 10;
											if (x % 10 == 3) {
												System.out.print(" " + i);
											}
										}
									}
								}
							}
						}
					}
				} int x = i; x i if (x % 3 == 0) {
						System.out.print(" " + i);
					}
					else {
						if (x % 10 == 3) {
							System.out.print(" " + i);
						}
						else {
							x /= 10;
							if (x % 10 == 3) {
								System.out.print(" " + i);
							}
							else {
								x /= 10;
								if (x % 10 == 3) {
									System.out.print(" " + i);
								}
								else {
									x /= 10;
									if (x % 10 == 3) {
										System.out.print(" " + i);
									}
									else {
										x /= 10;
										if (x % 10 == 3) {
											System.out.print(" " + i);
										}
										else {
											x /= 10;
											if (x % 10 == 3) {
												System.out.print(" " + i);
											}
										}
									}
								}
							}
						}
					} 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 {
						if (x % 10 == 3) {
							System.out.print(" " + i);
						}
						else {
							x /= 10;
							if (x % 10 == 3) {
								System.out.print(" " + i);
							}
							else {
								x /= 10;
								if (x % 10 == 3) {
									System.out.print(" " + i);
								}
								else {
									x /= 10;
									if (x % 10 == 3) {
										System.out.print(" " + i);
									}
									else {
										x /= 10;
										if (x % 10 == 3) {
											System.out.print(" " + i);
										}
										else {
											x /= 10;
											if (x % 10 == 3) {
												System.out.print(" " + i);
											}
										}
									}
								}
							}
						}
					} if (x % 10 == 3) {
							System.out.print(" " + i);
						}
						else {
							x /= 10;
							if (x % 10 == 3) {
								System.out.print(" " + i);
							}
							else {
								x /= 10;
								if (x % 10 == 3) {
									System.out.print(" " + i);
								}
								else {
									x /= 10;
									if (x % 10 == 3) {
										System.out.print(" " + i);
									}
									else {
										x /= 10;
										if (x % 10 == 3) {
											System.out.print(" " + i);
										}
										else {
											x /= 10;
											if (x % 10 == 3) {
												System.out.print(" " + i);
											}
										}
									}
								}
							}
						} x % 10 == 3 x % 10 x 10 3 {
							System.out.print(" " + i);
						} System.out.print(" " + i) System.out.print System.out System System.out " " + i " " i {
							x /= 10;
							if (x % 10 == 3) {
								System.out.print(" " + i);
							}
							else {
								x /= 10;
								if (x % 10 == 3) {
									System.out.print(" " + i);
								}
								else {
									x /= 10;
									if (x % 10 == 3) {
										System.out.print(" " + i);
									}
									else {
										x /= 10;
										if (x % 10 == 3) {
											System.out.print(" " + i);
										}
										else {
											x /= 10;
											if (x % 10 == 3) {
												System.out.print(" " + i);
											}
										}
									}
								}
							}
						} x /= 10 x 10 if (x % 10 == 3) {
								System.out.print(" " + i);
							}
							else {
								x /= 10;
								if (x % 10 == 3) {
									System.out.print(" " + i);
								}
								else {
									x /= 10;
									if (x % 10 == 3) {
										System.out.print(" " + i);
									}
									else {
										x /= 10;
										if (x % 10 == 3) {
											System.out.print(" " + i);
										}
										else {
											x /= 10;
											if (x % 10 == 3) {
												System.out.print(" " + i);
											}
										}
									}
								}
							} x % 10 == 3 x % 10 x 10 3 {
								System.out.print(" " + i);
							} System.out.print(" " + i) System.out.print System.out System System.out " " + i " " i {
								x /= 10;
								if (x % 10 == 3) {
									System.out.print(" " + i);
								}
								else {
									x /= 10;
									if (x % 10 == 3) {
										System.out.print(" " + i);
									}
									else {
										x /= 10;
										if (x % 10 == 3) {
											System.out.print(" " + i);
										}
										else {
											x /= 10;
											if (x % 10 == 3) {
												System.out.print(" " + i);
											}
										}
									}
								}
							} x /= 10 x 10 if (x % 10 == 3) {
									System.out.print(" " + i);
								}
								else {
									x /= 10;
									if (x % 10 == 3) {
										System.out.print(" " + i);
									}
									else {
										x /= 10;
										if (x % 10 == 3) {
											System.out.print(" " + i);
										}
										else {
											x /= 10;
											if (x % 10 == 3) {
												System.out.print(" " + i);
											}
										}
									}
								} x % 10 == 3 x % 10 x 10 3 {
									System.out.print(" " + i);
								} System.out.print(" " + i) System.out.print System.out System System.out " " + i " " i {
									x /= 10;
									if (x % 10 == 3) {
										System.out.print(" " + i);
									}
									else {
										x /= 10;
										if (x % 10 == 3) {
											System.out.print(" " + i);
										}
										else {
											x /= 10;
											if (x % 10 == 3) {
												System.out.print(" " + i);
											}
										}
									}
								} x /= 10 x 10 if (x % 10 == 3) {
										System.out.print(" " + i);
									}
									else {
										x /= 10;
										if (x % 10 == 3) {
											System.out.print(" " + i);
										}
										else {
											x /= 10;
											if (x % 10 == 3) {
												System.out.print(" " + i);
											}
										}
									} x % 10 == 3 x % 10 x 10 3 {
										System.out.print(" " + i);
									} System.out.print(" " + i) System.out.print System.out System System.out " " + i " " i {
										x /= 10;
										if (x % 10 == 3) {
											System.out.print(" " + i);
										}
										else {
											x /= 10;
											if (x % 10 == 3) {
												System.out.print(" " + i);
											}
										}
									} x /= 10 x 10 if (x % 10 == 3) {
											System.out.print(" " + i);
										}
										else {
											x /= 10;
											if (x % 10 == 3) {
												System.out.print(" " + i);
											}
										} x % 10 == 3 x % 10 x 10 3 {
											System.out.print(" " + i);
										} System.out.print(" " + i) System.out.print System.out System System.out " " + i " " i {
											x /= 10;
											if (x % 10 == 3) {
												System.out.print(" " + i);
											}
										} x /= 10 x 10 if (x % 10 == 3) {
												System.out.print(" " + i);
											} x % 10 == 3 x % 10 x 10 3 {
												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));
		String buffer;
		try {
			while ((buffer = reader.readLine())  != null) {
				int n = Integer.valueOf(buffer.substring(0, buffer.indexOf(" ") == -1 ? buffer.length() : buffer.indexOf(" ")));

				for (int i = 1; i <= n; i++) {
					int x = i;
					if (x % 3 == 0) {
						System.out.print(" " + i);
					}
					else {
						if (x % 10 == 3) {
							System.out.print(" " + i);
						}
						else {
							x /= 10;
							if (x % 10 == 3) {
								System.out.print(" " + i);
							}
							else {
								x /= 10;
								if (x % 10 == 3) {
									System.out.print(" " + i);
								}
								else {
									x /= 10;
									if (x % 10 == 3) {
										System.out.print(" " + i);
									}
									else {
										x /= 10;
										if (x % 10 == 3) {
											System.out.print(" " + i);
										}
										else {
											x /= 10;
											if (x % 10 == 3) {
												System.out.print(" " + i);
											}
										}
									}
								}
							}
						}
					}
				}
				System.out.println();
			}
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}
} public class Main {

	public static void main(String[] args) {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		String buffer;
		try {
			while ((buffer = reader.readLine())  != null) {
				int n = Integer.valueOf(buffer.substring(0, buffer.indexOf(" ") == -1 ? buffer.length() : buffer.indexOf(" ")));

				for (int i = 1; i <= n; i++) {
					int x = i;
					if (x % 3 == 0) {
						System.out.print(" " + i);
					}
					else {
						if (x % 10 == 3) {
							System.out.print(" " + i);
						}
						else {
							x /= 10;
							if (x % 10 == 3) {
								System.out.print(" " + i);
							}
							else {
								x /= 10;
								if (x % 10 == 3) {
									System.out.print(" " + i);
								}
								else {
									x /= 10;
									if (x % 10 == 3) {
										System.out.print(" " + i);
									}
									else {
										x /= 10;
										if (x % 10 == 3) {
											System.out.print(" " + i);
										}
										else {
											x /= 10;
											if (x % 10 == 3) {
												System.out.print(" " + i);
											}
										}
									}
								}
							}
						}
					}
				}
				System.out.println();
			}
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}
} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		String buffer;
		try {
			while ((buffer = reader.readLine())  != null) {
				int n = Integer.valueOf(buffer.substring(0, buffer.indexOf(" ") == -1 ? buffer.length() : buffer.indexOf(" ")));

				for (int i = 1; i <= n; i++) {
					int x = i;
					if (x % 3 == 0) {
						System.out.print(" " + i);
					}
					else {
						if (x % 10 == 3) {
							System.out.print(" " + i);
						}
						else {
							x /= 10;
							if (x % 10 == 3) {
								System.out.print(" " + i);
							}
							else {
								x /= 10;
								if (x % 10 == 3) {
									System.out.print(" " + i);
								}
								else {
									x /= 10;
									if (x % 10 == 3) {
										System.out.print(" " + i);
									}
									else {
										x /= 10;
										if (x % 10 == 3) {
											System.out.print(" " + i);
										}
										else {
											x /= 10;
											if (x % 10 == 3) {
												System.out.print(" " + i);
											}
										}
									}
								}
							}
						}
					}
				}
				System.out.println();
			}
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}
}