import java.io.IOException;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws IOException {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int i = 1;
		do {
			int 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;
						}
					}
				}
			}
		} while (++i <= n);
		System.out.println("");
	}
} import java.io.IOException; IOException java.io import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) throws IOException {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int i = 1;
		do {
			int 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;
						}
					}
				}
			}
		} while (++i <= n);
		System.out.println("");
	}
} Main public static void main(String[] args) throws IOException {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int i = 1;
		do {
			int 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;
						}
					}
				}
			}
		} while (++i <= n);
		System.out.println("");
	} main {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int i = 1;
		do {
			int 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;
						}
					}
				}
			}
		} while (++i <= n);
		System.out.println("");
	} Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int n = scanner.nextInt(); n scanner.nextInt() scanner.nextInt scanner int i = 1; i 1 do {
			int 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;
						}
					}
				}
			}
		} while (++i <= n); ++i <= n ++i i n {
			int 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;
						}
					}
				}
			}
		} int 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; System.out.println("") System.out.println System.out System System.out "" String[] args args public class Main {
	public static void main(String[] args) throws IOException {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int i = 1;
		do {
			int 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;
						}
					}
				}
			}
		} while (++i <= n);
		System.out.println("");
	}
} public class Main {
	public static void main(String[] args) throws IOException {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int i = 1;
		do {
			int 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;
						}
					}
				}
			}
		} while (++i <= n);
		System.out.println("");
	}
} Main
import java.io.IOException;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws IOException {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int i = 1;
		do {
			int 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;
						}
					}
				}
			}
		} while (++i <= n);
		System.out.println("");
	}
}