

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner in = new Scanner(System.in);

		int num = in.nextInt();
		int count = 1;

		for (count = 1; count <= num; count++) {

			// 3??§?????????????????°?????¨???
			if (count % 3 == 0) {

				System.out.print(" " + count);

				// ???????????????3?????°?????¨???
			} else if (count % 10 == 3) {

				System.out.print(" " + count);

				// else if(count / 10 == 3)
			} else {

				int x = count;
				int display = 0;

				while (x > 10) {
					x /= 10;

					if (x % 10 == 3) {
						display = count;
					}
				}
				if(display != 0) {
					System.out.print(" " + display);
				}
			}
		}
		System.out.println("");
	}

} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {

		Scanner in = new Scanner(System.in);

		int num = in.nextInt();
		int count = 1;

		for (count = 1; count <= num; count++) {

			// 3??§?????????????????°?????¨???
			if (count % 3 == 0) {

				System.out.print(" " + count);

				// ???????????????3?????°?????¨???
			} else if (count % 10 == 3) {

				System.out.print(" " + count);

				// else if(count / 10 == 3)
			} else {

				int x = count;
				int display = 0;

				while (x > 10) {
					x /= 10;

					if (x % 10 == 3) {
						display = count;
					}
				}
				if(display != 0) {
					System.out.print(" " + display);
				}
			}
		}
		System.out.println("");
	}

} Main public static void main(String[] args) {

		Scanner in = new Scanner(System.in);

		int num = in.nextInt();
		int count = 1;

		for (count = 1; count <= num; count++) {

			// 3??§?????????????????°?????¨???
			if (count % 3 == 0) {

				System.out.print(" " + count);

				// ???????????????3?????°?????¨???
			} else if (count % 10 == 3) {

				System.out.print(" " + count);

				// else if(count / 10 == 3)
			} else {

				int x = count;
				int display = 0;

				while (x > 10) {
					x /= 10;

					if (x % 10 == 3) {
						display = count;
					}
				}
				if(display != 0) {
					System.out.print(" " + display);
				}
			}
		}
		System.out.println("");
	} main {

		Scanner in = new Scanner(System.in);

		int num = in.nextInt();
		int count = 1;

		for (count = 1; count <= num; count++) {

			// 3??§?????????????????°?????¨???
			if (count % 3 == 0) {

				System.out.print(" " + count);

				// ???????????????3?????°?????¨???
			} else if (count % 10 == 3) {

				System.out.print(" " + count);

				// else if(count / 10 == 3)
			} else {

				int x = count;
				int display = 0;

				while (x > 10) {
					x /= 10;

					if (x % 10 == 3) {
						display = count;
					}
				}
				if(display != 0) {
					System.out.print(" " + display);
				}
			}
		}
		System.out.println("");
	} Scanner in = new Scanner(System.in); in new Scanner(System.in) int num = in.nextInt(); num in.nextInt() in.nextInt in int count = 1; count 1 for (count = 1; count <= num; count++) {

			// 3??§?????????????????°?????¨???
			if (count % 3 == 0) {

				System.out.print(" " + count);

				// ???????????????3?????°?????¨???
			} else if (count % 10 == 3) {

				System.out.print(" " + count);

				// else if(count / 10 == 3)
			} else {

				int x = count;
				int display = 0;

				while (x > 10) {
					x /= 10;

					if (x % 10 == 3) {
						display = count;
					}
				}
				if(display != 0) {
					System.out.print(" " + display);
				}
			}
		} count = 1; count = 1 count 1 count <= num count num count++ count++ count {

			// 3??§?????????????????°?????¨???
			if (count % 3 == 0) {

				System.out.print(" " + count);

				// ???????????????3?????°?????¨???
			} else if (count % 10 == 3) {

				System.out.print(" " + count);

				// else if(count / 10 == 3)
			} else {

				int x = count;
				int display = 0;

				while (x > 10) {
					x /= 10;

					if (x % 10 == 3) {
						display = count;
					}
				}
				if(display != 0) {
					System.out.print(" " + display);
				}
			}
		} {

			// 3??§?????????????????°?????¨???
			if (count % 3 == 0) {

				System.out.print(" " + count);

				// ???????????????3?????°?????¨???
			} else if (count % 10 == 3) {

				System.out.print(" " + count);

				// else if(count / 10 == 3)
			} else {

				int x = count;
				int display = 0;

				while (x > 10) {
					x /= 10;

					if (x % 10 == 3) {
						display = count;
					}
				}
				if(display != 0) {
					System.out.print(" " + display);
				}
			}
		} if (count % 3 == 0) {

				System.out.print(" " + count);

				// ???????????????3?????°?????¨???
			} else if (count % 10 == 3) {

				System.out.print(" " + count);

				// else if(count / 10 == 3)
			} else {

				int x = count;
				int display = 0;

				while (x > 10) {
					x /= 10;

					if (x % 10 == 3) {
						display = count;
					}
				}
				if(display != 0) {
					System.out.print(" " + display);
				}
			} count % 3 == 0 count % 3 count 3 0 {

				System.out.print(" " + count);

				// ???????????????3?????°?????¨???
			} System.out.print(" " + count) System.out.print System.out System System.out " " + count " " count if (count % 10 == 3) {

				System.out.print(" " + count);

				// else if(count / 10 == 3)
			} else {

				int x = count;
				int display = 0;

				while (x > 10) {
					x /= 10;

					if (x % 10 == 3) {
						display = count;
					}
				}
				if(display != 0) {
					System.out.print(" " + display);
				}
			} count % 10 == 3 count % 10 count 10 3 {

				System.out.print(" " + count);

				// else if(count / 10 == 3)
			} System.out.print(" " + count) System.out.print System.out System System.out " " + count " " count {

				int x = count;
				int display = 0;

				while (x > 10) {
					x /= 10;

					if (x % 10 == 3) {
						display = count;
					}
				}
				if(display != 0) {
					System.out.print(" " + display);
				}
			} int x = count; x count int display = 0; display 0 while (x > 10) {
					x /= 10;

					if (x % 10 == 3) {
						display = count;
					}
				} x > 10 x 10 {
					x /= 10;

					if (x % 10 == 3) {
						display = count;
					}
				} x /= 10 x 10 if (x % 10 == 3) {
						display = count;
					} x % 10 == 3 x % 10 x 10 3 {
						display = count;
					} display = count display count if(display != 0) {
					System.out.print(" " + display);
				} display != 0 display 0 {
					System.out.print(" " + display);
				} System.out.print(" " + display) System.out.print System.out System System.out " " + display " " display System.out.println("") System.out.println System.out System System.out "" String[] args args public class Main {

	public static void main(String[] args) {

		Scanner in = new Scanner(System.in);

		int num = in.nextInt();
		int count = 1;

		for (count = 1; count <= num; count++) {

			// 3??§?????????????????°?????¨???
			if (count % 3 == 0) {

				System.out.print(" " + count);

				// ???????????????3?????°?????¨???
			} else if (count % 10 == 3) {

				System.out.print(" " + count);

				// else if(count / 10 == 3)
			} else {

				int x = count;
				int display = 0;

				while (x > 10) {
					x /= 10;

					if (x % 10 == 3) {
						display = count;
					}
				}
				if(display != 0) {
					System.out.print(" " + display);
				}
			}
		}
		System.out.println("");
	}

} public class Main {

	public static void main(String[] args) {

		Scanner in = new Scanner(System.in);

		int num = in.nextInt();
		int count = 1;

		for (count = 1; count <= num; count++) {

			// 3??§?????????????????°?????¨???
			if (count % 3 == 0) {

				System.out.print(" " + count);

				// ???????????????3?????°?????¨???
			} else if (count % 10 == 3) {

				System.out.print(" " + count);

				// else if(count / 10 == 3)
			} else {

				int x = count;
				int display = 0;

				while (x > 10) {
					x /= 10;

					if (x % 10 == 3) {
						display = count;
					}
				}
				if(display != 0) {
					System.out.print(" " + display);
				}
			}
		}
		System.out.println("");
	}

} Main


import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner in = new Scanner(System.in);

		int num = in.nextInt();
		int count = 1;

		for (count = 1; count <= num; count++) {

			// 3??§?????????????????°?????¨???
			if (count % 3 == 0) {

				System.out.print(" " + count);

				// ???????????????3?????°?????¨???
			} else if (count % 10 == 3) {

				System.out.print(" " + count);

				// else if(count / 10 == 3)
			} else {

				int x = count;
				int display = 0;

				while (x > 10) {
					x /= 10;

					if (x % 10 == 3) {
						display = count;
					}
				}
				if(display != 0) {
					System.out.print(" " + display);
				}
			}
		}
		System.out.println("");
	}

}