import java.util.Scanner;

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

} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int x;
		String str = "";
		for (int i = 1; i <= n; i++) {
			x = i;
			if (x % 3 == 0) {
				str += " " + x;
			} else {
				while (x != 0) {
					if (x % 10 == 3) {
						str += " " + i;
						break;
					}
					x /= 10;
				}
			}
		}
		System.out.println(str);
	}

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

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

} Main
import java.util.Scanner;

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

}