import java.util.Scanner;

public class Main {

	public static Scanner scanner = new Scanner(System.in);

	public static void main(String[] args) {

		int n = input();
		StringBuilder sb = new StringBuilder();

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

			if (i % 3 == 0) {

				sb.append(" " + i);

			} else {

				int x = i;

				while (x != 0) {

					if (x % 10 == 3) {

						sb.append(" " + i);
						break;

					} else {

						x = x / 10;

					}
				}
			}
		}

		System.out.println(sb);

		close();

	}

	public static int input() {

		return scanner.nextInt();

	}

	public static void close() {

		if (scanner != null) {

			scanner.close();

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

	public static Scanner scanner = new Scanner(System.in);

	public static void main(String[] args) {

		int n = input();
		StringBuilder sb = new StringBuilder();

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

			if (i % 3 == 0) {

				sb.append(" " + i);

			} else {

				int x = i;

				while (x != 0) {

					if (x % 10 == 3) {

						sb.append(" " + i);
						break;

					} else {

						x = x / 10;

					}
				}
			}
		}

		System.out.println(sb);

		close();

	}

	public static int input() {

		return scanner.nextInt();

	}

	public static void close() {

		if (scanner != null) {

			scanner.close();

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

		int n = input();
		StringBuilder sb = new StringBuilder();

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

			if (i % 3 == 0) {

				sb.append(" " + i);

			} else {

				int x = i;

				while (x != 0) {

					if (x % 10 == 3) {

						sb.append(" " + i);
						break;

					} else {

						x = x / 10;

					}
				}
			}
		}

		System.out.println(sb);

		close();

	} main {

		int n = input();
		StringBuilder sb = new StringBuilder();

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

			if (i % 3 == 0) {

				sb.append(" " + i);

			} else {

				int x = i;

				while (x != 0) {

					if (x % 10 == 3) {

						sb.append(" " + i);
						break;

					} else {

						x = x / 10;

					}
				}
			}
		}

		System.out.println(sb);

		close();

	} int n = input(); n input() input StringBuilder sb = new StringBuilder(); sb new StringBuilder() for (int i = 1 ; i <= n; i++) {

			if (i % 3 == 0) {

				sb.append(" " + i);

			} else {

				int x = i;

				while (x != 0) {

					if (x % 10 == 3) {

						sb.append(" " + i);
						break;

					} else {

						x = x / 10;

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

			if (i % 3 == 0) {

				sb.append(" " + i);

			} else {

				int x = i;

				while (x != 0) {

					if (x % 10 == 3) {

						sb.append(" " + i);
						break;

					} else {

						x = x / 10;

					}
				}
			}
		} {

			if (i % 3 == 0) {

				sb.append(" " + i);

			} else {

				int x = i;

				while (x != 0) {

					if (x % 10 == 3) {

						sb.append(" " + i);
						break;

					} else {

						x = x / 10;

					}
				}
			}
		} if (i % 3 == 0) {

				sb.append(" " + i);

			} else {

				int x = i;

				while (x != 0) {

					if (x % 10 == 3) {

						sb.append(" " + i);
						break;

					} else {

						x = x / 10;

					}
				}
			} i % 3 == 0 i % 3 i 3 0 {

				sb.append(" " + i);

			} sb.append(" " + i) sb.append sb " " + i " " i {

				int x = i;

				while (x != 0) {

					if (x % 10 == 3) {

						sb.append(" " + i);
						break;

					} else {

						x = x / 10;

					}
				}
			} int x = i; x i while (x != 0) {

					if (x % 10 == 3) {

						sb.append(" " + i);
						break;

					} else {

						x = x / 10;

					}
				} x != 0 x 0 {

					if (x % 10 == 3) {

						sb.append(" " + i);
						break;

					} else {

						x = x / 10;

					}
				} if (x % 10 == 3) {

						sb.append(" " + i);
						break;

					} else {

						x = x / 10;

					} x % 10 == 3 x % 10 x 10 3 {

						sb.append(" " + i);
						break;

					} sb.append(" " + i) sb.append sb " " + i " " i break; {

						x = x / 10;

					} x = x / 10 x x / 10 x 10 System.out.println(sb) System.out.println System.out System System.out sb close() close String[] args args public static int input() {

		return scanner.nextInt();

	} input {

		return scanner.nextInt();

	} return scanner.nextInt(); scanner.nextInt() scanner.nextInt scanner public static void close() {

		if (scanner != null) {

			scanner.close();

		}
	} close {

		if (scanner != null) {

			scanner.close();

		}
	} if (scanner != null) {

			scanner.close();

		} scanner != null scanner null {

			scanner.close();

		} scanner.close() scanner.close scanner public class Main {

	public static Scanner scanner = new Scanner(System.in);

	public static void main(String[] args) {

		int n = input();
		StringBuilder sb = new StringBuilder();

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

			if (i % 3 == 0) {

				sb.append(" " + i);

			} else {

				int x = i;

				while (x != 0) {

					if (x % 10 == 3) {

						sb.append(" " + i);
						break;

					} else {

						x = x / 10;

					}
				}
			}
		}

		System.out.println(sb);

		close();

	}

	public static int input() {

		return scanner.nextInt();

	}

	public static void close() {

		if (scanner != null) {

			scanner.close();

		}
	}
} public class Main {

	public static Scanner scanner = new Scanner(System.in);

	public static void main(String[] args) {

		int n = input();
		StringBuilder sb = new StringBuilder();

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

			if (i % 3 == 0) {

				sb.append(" " + i);

			} else {

				int x = i;

				while (x != 0) {

					if (x % 10 == 3) {

						sb.append(" " + i);
						break;

					} else {

						x = x / 10;

					}
				}
			}
		}

		System.out.println(sb);

		close();

	}

	public static int input() {

		return scanner.nextInt();

	}

	public static void close() {

		if (scanner != null) {

			scanner.close();

		}
	}
} Main
import java.util.Scanner;

public class Main {

	public static Scanner scanner = new Scanner(System.in);

	public static void main(String[] args) {

		int n = input();
		StringBuilder sb = new StringBuilder();

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

			if (i % 3 == 0) {

				sb.append(" " + i);

			} else {

				int x = i;

				while (x != 0) {

					if (x % 10 == 3) {

						sb.append(" " + i);
						break;

					} else {

						x = x / 10;

					}
				}
			}
		}

		System.out.println(sb);

		close();

	}

	public static int input() {

		return scanner.nextInt();

	}

	public static void close() {

		if (scanner != null) {

			scanner.close();

		}
	}
}