import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) {
		try {
			BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
			StringBuilder answer = new StringBuilder();
			int n = Integer.parseInt(input.readLine());
			for (int i = 3; i <= n; i++) {
				if (i % 3 == 0) {
					answer.append(" ").append(String.valueOf(i));
				} else {
					int tmp = i;
					while (tmp != 0) {
						if (tmp % 10 == 3) {
							answer.append(" ").append(String.valueOf(i));
							break;
						}
						tmp /= 10;
					}
				}
			}
			System.out.println(answer.toString());
		} catch (Exception e) {
			e.printStackTrace();
		}

	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {
	public static void main(String[] args) {
		try {
			BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
			StringBuilder answer = new StringBuilder();
			int n = Integer.parseInt(input.readLine());
			for (int i = 3; i <= n; i++) {
				if (i % 3 == 0) {
					answer.append(" ").append(String.valueOf(i));
				} else {
					int tmp = i;
					while (tmp != 0) {
						if (tmp % 10 == 3) {
							answer.append(" ").append(String.valueOf(i));
							break;
						}
						tmp /= 10;
					}
				}
			}
			System.out.println(answer.toString());
		} catch (Exception e) {
			e.printStackTrace();
		}

	}
} Main public static void main(String[] args) {
		try {
			BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
			StringBuilder answer = new StringBuilder();
			int n = Integer.parseInt(input.readLine());
			for (int i = 3; i <= n; i++) {
				if (i % 3 == 0) {
					answer.append(" ").append(String.valueOf(i));
				} else {
					int tmp = i;
					while (tmp != 0) {
						if (tmp % 10 == 3) {
							answer.append(" ").append(String.valueOf(i));
							break;
						}
						tmp /= 10;
					}
				}
			}
			System.out.println(answer.toString());
		} catch (Exception e) {
			e.printStackTrace();
		}

	} main {
		try {
			BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
			StringBuilder answer = new StringBuilder();
			int n = Integer.parseInt(input.readLine());
			for (int i = 3; i <= n; i++) {
				if (i % 3 == 0) {
					answer.append(" ").append(String.valueOf(i));
				} else {
					int tmp = i;
					while (tmp != 0) {
						if (tmp % 10 == 3) {
							answer.append(" ").append(String.valueOf(i));
							break;
						}
						tmp /= 10;
					}
				}
			}
			System.out.println(answer.toString());
		} catch (Exception e) {
			e.printStackTrace();
		}

	} try {
			BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
			StringBuilder answer = new StringBuilder();
			int n = Integer.parseInt(input.readLine());
			for (int i = 3; i <= n; i++) {
				if (i % 3 == 0) {
					answer.append(" ").append(String.valueOf(i));
				} else {
					int tmp = i;
					while (tmp != 0) {
						if (tmp % 10 == 3) {
							answer.append(" ").append(String.valueOf(i));
							break;
						}
						tmp /= 10;
					}
				}
			}
			System.out.println(answer.toString());
		} catch (Exception e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		} Exception e {
			e.printStackTrace();
		} e.printStackTrace() e.printStackTrace e {
			BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
			StringBuilder answer = new StringBuilder();
			int n = Integer.parseInt(input.readLine());
			for (int i = 3; i <= n; i++) {
				if (i % 3 == 0) {
					answer.append(" ").append(String.valueOf(i));
				} else {
					int tmp = i;
					while (tmp != 0) {
						if (tmp % 10 == 3) {
							answer.append(" ").append(String.valueOf(i));
							break;
						}
						tmp /= 10;
					}
				}
			}
			System.out.println(answer.toString());
		} BufferedReader input = new BufferedReader(new InputStreamReader(System.in)); input new BufferedReader(new InputStreamReader(System.in)) StringBuilder answer = new StringBuilder(); answer new StringBuilder() int n = Integer.parseInt(input.readLine()); n Integer.parseInt(input.readLine()) Integer.parseInt Integer input.readLine() input.readLine input for (int i = 3; i <= n; i++) {
				if (i % 3 == 0) {
					answer.append(" ").append(String.valueOf(i));
				} else {
					int tmp = i;
					while (tmp != 0) {
						if (tmp % 10 == 3) {
							answer.append(" ").append(String.valueOf(i));
							break;
						}
						tmp /= 10;
					}
				}
			} int i = 3; int i = 3; i 3 i <= n i n i++ i++ i {
				if (i % 3 == 0) {
					answer.append(" ").append(String.valueOf(i));
				} else {
					int tmp = i;
					while (tmp != 0) {
						if (tmp % 10 == 3) {
							answer.append(" ").append(String.valueOf(i));
							break;
						}
						tmp /= 10;
					}
				}
			} {
				if (i % 3 == 0) {
					answer.append(" ").append(String.valueOf(i));
				} else {
					int tmp = i;
					while (tmp != 0) {
						if (tmp % 10 == 3) {
							answer.append(" ").append(String.valueOf(i));
							break;
						}
						tmp /= 10;
					}
				}
			} if (i % 3 == 0) {
					answer.append(" ").append(String.valueOf(i));
				} else {
					int tmp = i;
					while (tmp != 0) {
						if (tmp % 10 == 3) {
							answer.append(" ").append(String.valueOf(i));
							break;
						}
						tmp /= 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 tmp = i;
					while (tmp != 0) {
						if (tmp % 10 == 3) {
							answer.append(" ").append(String.valueOf(i));
							break;
						}
						tmp /= 10;
					}
				} int tmp = i; tmp i while (tmp != 0) {
						if (tmp % 10 == 3) {
							answer.append(" ").append(String.valueOf(i));
							break;
						}
						tmp /= 10;
					} tmp != 0 tmp 0 {
						if (tmp % 10 == 3) {
							answer.append(" ").append(String.valueOf(i));
							break;
						}
						tmp /= 10;
					} if (tmp % 10 == 3) {
							answer.append(" ").append(String.valueOf(i));
							break;
						} tmp % 10 == 3 tmp % 10 tmp 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; tmp /= 10 tmp 10 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) {
		try {
			BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
			StringBuilder answer = new StringBuilder();
			int n = Integer.parseInt(input.readLine());
			for (int i = 3; i <= n; i++) {
				if (i % 3 == 0) {
					answer.append(" ").append(String.valueOf(i));
				} else {
					int tmp = i;
					while (tmp != 0) {
						if (tmp % 10 == 3) {
							answer.append(" ").append(String.valueOf(i));
							break;
						}
						tmp /= 10;
					}
				}
			}
			System.out.println(answer.toString());
		} catch (Exception e) {
			e.printStackTrace();
		}

	}
} public class Main {
	public static void main(String[] args) {
		try {
			BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
			StringBuilder answer = new StringBuilder();
			int n = Integer.parseInt(input.readLine());
			for (int i = 3; i <= n; i++) {
				if (i % 3 == 0) {
					answer.append(" ").append(String.valueOf(i));
				} else {
					int tmp = i;
					while (tmp != 0) {
						if (tmp % 10 == 3) {
							answer.append(" ").append(String.valueOf(i));
							break;
						}
						tmp /= 10;
					}
				}
			}
			System.out.println(answer.toString());
		} catch (Exception e) {
			e.printStackTrace();
		}

	}
} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) {
		try {
			BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
			StringBuilder answer = new StringBuilder();
			int n = Integer.parseInt(input.readLine());
			for (int i = 3; i <= n; i++) {
				if (i % 3 == 0) {
					answer.append(" ").append(String.valueOf(i));
				} else {
					int tmp = i;
					while (tmp != 0) {
						if (tmp % 10 == 3) {
							answer.append(" ").append(String.valueOf(i));
							break;
						}
						tmp /= 10;
					}
				}
			}
			System.out.println(answer.toString());
		} catch (Exception e) {
			e.printStackTrace();
		}

	}
}