import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);


				int j = sc.nextInt();
				int a;
				int flag = 0;

				for(int i = 1; i <= j; i++) {

					if(i % 3 == 0) {
						System.out.print(" " + i);
					} else {

						a = i;
						while(true) {

							if(a % 10 == 3) {
								flag = 1;
								break;
							}

							if(a < 10) {
								break;
							}
							a = a / 10;

						}

						if(flag == 1) {
							System.out.print(" " + i);
							flag = 0;
						}

					}
				}
				System.out.println();
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);


				int j = sc.nextInt();
				int a;
				int flag = 0;

				for(int i = 1; i <= j; i++) {

					if(i % 3 == 0) {
						System.out.print(" " + i);
					} else {

						a = i;
						while(true) {

							if(a % 10 == 3) {
								flag = 1;
								break;
							}

							if(a < 10) {
								break;
							}
							a = a / 10;

						}

						if(flag == 1) {
							System.out.print(" " + i);
							flag = 0;
						}

					}
				}
				System.out.println();
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);


				int j = sc.nextInt();
				int a;
				int flag = 0;

				for(int i = 1; i <= j; i++) {

					if(i % 3 == 0) {
						System.out.print(" " + i);
					} else {

						a = i;
						while(true) {

							if(a % 10 == 3) {
								flag = 1;
								break;
							}

							if(a < 10) {
								break;
							}
							a = a / 10;

						}

						if(flag == 1) {
							System.out.print(" " + i);
							flag = 0;
						}

					}
				}
				System.out.println();
	} main {
		Scanner sc = new Scanner(System.in);


				int j = sc.nextInt();
				int a;
				int flag = 0;

				for(int i = 1; i <= j; i++) {

					if(i % 3 == 0) {
						System.out.print(" " + i);
					} else {

						a = i;
						while(true) {

							if(a % 10 == 3) {
								flag = 1;
								break;
							}

							if(a < 10) {
								break;
							}
							a = a / 10;

						}

						if(flag == 1) {
							System.out.print(" " + i);
							flag = 0;
						}

					}
				}
				System.out.println();
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int j = sc.nextInt(); j sc.nextInt() sc.nextInt sc int a; a int flag = 0; flag 0 for(int i = 1; i <= j; i++) {

					if(i % 3 == 0) {
						System.out.print(" " + i);
					} else {

						a = i;
						while(true) {

							if(a % 10 == 3) {
								flag = 1;
								break;
							}

							if(a < 10) {
								break;
							}
							a = a / 10;

						}

						if(flag == 1) {
							System.out.print(" " + i);
							flag = 0;
						}

					}
				} int i = 1; int i = 1; i 1 i <= j i j i++ i++ i {

					if(i % 3 == 0) {
						System.out.print(" " + i);
					} else {

						a = i;
						while(true) {

							if(a % 10 == 3) {
								flag = 1;
								break;
							}

							if(a < 10) {
								break;
							}
							a = a / 10;

						}

						if(flag == 1) {
							System.out.print(" " + i);
							flag = 0;
						}

					}
				} {

					if(i % 3 == 0) {
						System.out.print(" " + i);
					} else {

						a = i;
						while(true) {

							if(a % 10 == 3) {
								flag = 1;
								break;
							}

							if(a < 10) {
								break;
							}
							a = a / 10;

						}

						if(flag == 1) {
							System.out.print(" " + i);
							flag = 0;
						}

					}
				} if(i % 3 == 0) {
						System.out.print(" " + i);
					} else {

						a = i;
						while(true) {

							if(a % 10 == 3) {
								flag = 1;
								break;
							}

							if(a < 10) {
								break;
							}
							a = a / 10;

						}

						if(flag == 1) {
							System.out.print(" " + i);
							flag = 0;
						}

					} 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 {

						a = i;
						while(true) {

							if(a % 10 == 3) {
								flag = 1;
								break;
							}

							if(a < 10) {
								break;
							}
							a = a / 10;

						}

						if(flag == 1) {
							System.out.print(" " + i);
							flag = 0;
						}

					} a = i a i while(true) {

							if(a % 10 == 3) {
								flag = 1;
								break;
							}

							if(a < 10) {
								break;
							}
							a = a / 10;

						} true {

							if(a % 10 == 3) {
								flag = 1;
								break;
							}

							if(a < 10) {
								break;
							}
							a = a / 10;

						} if(a % 10 == 3) {
								flag = 1;
								break;
							} a % 10 == 3 a % 10 a 10 3 {
								flag = 1;
								break;
							} flag = 1 flag 1 break; if(a < 10) {
								break;
							} a < 10 a 10 {
								break;
							} break; a = a / 10 a a / 10 a 10 if(flag == 1) {
							System.out.print(" " + i);
							flag = 0;
						} flag == 1 flag 1 {
							System.out.print(" " + i);
							flag = 0;
						} System.out.print(" " + i) System.out.print System.out System System.out " " + i " " i flag = 0 flag 0 System.out.println() System.out.println System.out System System.out String[] args args public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);


				int j = sc.nextInt();
				int a;
				int flag = 0;

				for(int i = 1; i <= j; i++) {

					if(i % 3 == 0) {
						System.out.print(" " + i);
					} else {

						a = i;
						while(true) {

							if(a % 10 == 3) {
								flag = 1;
								break;
							}

							if(a < 10) {
								break;
							}
							a = a / 10;

						}

						if(flag == 1) {
							System.out.print(" " + i);
							flag = 0;
						}

					}
				}
				System.out.println();
	}
} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);


				int j = sc.nextInt();
				int a;
				int flag = 0;

				for(int i = 1; i <= j; i++) {

					if(i % 3 == 0) {
						System.out.print(" " + i);
					} else {

						a = i;
						while(true) {

							if(a % 10 == 3) {
								flag = 1;
								break;
							}

							if(a < 10) {
								break;
							}
							a = a / 10;

						}

						if(flag == 1) {
							System.out.print(" " + i);
							flag = 0;
						}

					}
				}
				System.out.println();
	}
} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);


				int j = sc.nextInt();
				int a;
				int flag = 0;

				for(int i = 1; i <= j; i++) {

					if(i % 3 == 0) {
						System.out.print(" " + i);
					} else {

						a = i;
						while(true) {

							if(a % 10 == 3) {
								flag = 1;
								break;
							}

							if(a < 10) {
								break;
							}
							a = a / 10;

						}

						if(flag == 1) {
							System.out.print(" " + i);
							flag = 0;
						}

					}
				}
				System.out.println();
	}
}