import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder answer = new StringBuilder();
		int n = sc.nextInt();
		int i = 1;

		if (n >= 3 && n <= 10000) {
			while (i <= n) {
				if (i % 3 == 0) {
					answer.append(" ").append(String.valueOf(i));
				} else {
					int x;
					x = i;
					while (x != 0) {
						if (x % 10 == 3) {
							answer.append(" ").append(String.valueOf(i));
							break;
						}
						x = x / 10;
					}
				}

				i++;
			}
		}
		System.out.println(answer.toString());

	}

} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder answer = new StringBuilder();
		int n = sc.nextInt();
		int i = 1;

		if (n >= 3 && n <= 10000) {
			while (i <= n) {
				if (i % 3 == 0) {
					answer.append(" ").append(String.valueOf(i));
				} else {
					int x;
					x = i;
					while (x != 0) {
						if (x % 10 == 3) {
							answer.append(" ").append(String.valueOf(i));
							break;
						}
						x = x / 10;
					}
				}

				i++;
			}
		}
		System.out.println(answer.toString());

	}

} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder answer = new StringBuilder();
		int n = sc.nextInt();
		int i = 1;

		if (n >= 3 && n <= 10000) {
			while (i <= n) {
				if (i % 3 == 0) {
					answer.append(" ").append(String.valueOf(i));
				} else {
					int x;
					x = i;
					while (x != 0) {
						if (x % 10 == 3) {
							answer.append(" ").append(String.valueOf(i));
							break;
						}
						x = x / 10;
					}
				}

				i++;
			}
		}
		System.out.println(answer.toString());

	} main {
		Scanner sc = new Scanner(System.in);
		StringBuilder answer = new StringBuilder();
		int n = sc.nextInt();
		int i = 1;

		if (n >= 3 && n <= 10000) {
			while (i <= n) {
				if (i % 3 == 0) {
					answer.append(" ").append(String.valueOf(i));
				} else {
					int x;
					x = i;
					while (x != 0) {
						if (x % 10 == 3) {
							answer.append(" ").append(String.valueOf(i));
							break;
						}
						x = x / 10;
					}
				}

				i++;
			}
		}
		System.out.println(answer.toString());

	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) StringBuilder answer = new StringBuilder(); answer new StringBuilder() int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int i = 1; i 1 if (n >= 3 && n <= 10000) {
			while (i <= n) {
				if (i % 3 == 0) {
					answer.append(" ").append(String.valueOf(i));
				} else {
					int x;
					x = i;
					while (x != 0) {
						if (x % 10 == 3) {
							answer.append(" ").append(String.valueOf(i));
							break;
						}
						x = x / 10;
					}
				}

				i++;
			}
		} n >= 3 && n <= 10000 n >= 3 n 3 n <= 10000 n 10000 {
			while (i <= n) {
				if (i % 3 == 0) {
					answer.append(" ").append(String.valueOf(i));
				} else {
					int x;
					x = i;
					while (x != 0) {
						if (x % 10 == 3) {
							answer.append(" ").append(String.valueOf(i));
							break;
						}
						x = x / 10;
					}
				}

				i++;
			}
		} while (i <= n) {
				if (i % 3 == 0) {
					answer.append(" ").append(String.valueOf(i));
				} else {
					int x;
					x = i;
					while (x != 0) {
						if (x % 10 == 3) {
							answer.append(" ").append(String.valueOf(i));
							break;
						}
						x = x / 10;
					}
				}

				i++;
			} i <= n i n {
				if (i % 3 == 0) {
					answer.append(" ").append(String.valueOf(i));
				} else {
					int x;
					x = i;
					while (x != 0) {
						if (x % 10 == 3) {
							answer.append(" ").append(String.valueOf(i));
							break;
						}
						x = x / 10;
					}
				}

				i++;
			} if (i % 3 == 0) {
					answer.append(" ").append(String.valueOf(i));
				} else {
					int x;
					x = i;
					while (x != 0) {
						if (x % 10 == 3) {
							answer.append(" ").append(String.valueOf(i));
							break;
						}
						x = x / 10;
					}
				} i % 3 == 0 i % 3 i 3 0 {
					answer.append(" ").append(String.valueOf(i));
				} answer.append(" ").append(String.valueOf(i)) answer.append(" ").append answer.append(" ") answer.append answer " " String.valueOf(i) String.valueOf String i {
					int x;
					x = i;
					while (x != 0) {
						if (x % 10 == 3) {
							answer.append(" ").append(String.valueOf(i));
							break;
						}
						x = x / 10;
					}
				} int x; x x = i x i while (x != 0) {
						if (x % 10 == 3) {
							answer.append(" ").append(String.valueOf(i));
							break;
						}
						x = x / 10;
					} x != 0 x 0 {
						if (x % 10 == 3) {
							answer.append(" ").append(String.valueOf(i));
							break;
						}
						x = x / 10;
					} if (x % 10 == 3) {
							answer.append(" ").append(String.valueOf(i));
							break;
						} x % 10 == 3 x % 10 x 10 3 {
							answer.append(" ").append(String.valueOf(i));
							break;
						} answer.append(" ").append(String.valueOf(i)) answer.append(" ").append answer.append(" ") answer.append answer " " String.valueOf(i) String.valueOf String i break; x = x / 10 x x / 10 x 10 i++ i System.out.println(answer.toString()) System.out.println System.out System System.out answer.toString() answer.toString answer String[] args args public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder answer = new StringBuilder();
		int n = sc.nextInt();
		int i = 1;

		if (n >= 3 && n <= 10000) {
			while (i <= n) {
				if (i % 3 == 0) {
					answer.append(" ").append(String.valueOf(i));
				} else {
					int x;
					x = i;
					while (x != 0) {
						if (x % 10 == 3) {
							answer.append(" ").append(String.valueOf(i));
							break;
						}
						x = x / 10;
					}
				}

				i++;
			}
		}
		System.out.println(answer.toString());

	}

} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder answer = new StringBuilder();
		int n = sc.nextInt();
		int i = 1;

		if (n >= 3 && n <= 10000) {
			while (i <= n) {
				if (i % 3 == 0) {
					answer.append(" ").append(String.valueOf(i));
				} else {
					int x;
					x = i;
					while (x != 0) {
						if (x % 10 == 3) {
							answer.append(" ").append(String.valueOf(i));
							break;
						}
						x = x / 10;
					}
				}

				i++;
			}
		}
		System.out.println(answer.toString());

	}

} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder answer = new StringBuilder();
		int n = sc.nextInt();
		int i = 1;

		if (n >= 3 && n <= 10000) {
			while (i <= n) {
				if (i % 3 == 0) {
					answer.append(" ").append(String.valueOf(i));
				} else {
					int x;
					x = i;
					while (x != 0) {
						if (x % 10 == 3) {
							answer.append(" ").append(String.valueOf(i));
							break;
						}
						x = x / 10;
					}
				}

				i++;
			}
		}
		System.out.println(answer.toString());

	}

}