import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		boolean inclued3 = false;

		for (int i = 1, a; i <= n; i++) {
			a = 1;
			while (i / a >= 1) {
				if (i % (a * 10) / a == 3) {
					inclued3 = true;
					break;
				} else {
					inclued3 = false;
				}
				a *= 10;
			}

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

		}
		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 n = sc.nextInt();
		boolean inclued3 = false;

		for (int i = 1, a; i <= n; i++) {
			a = 1;
			while (i / a >= 1) {
				if (i % (a * 10) / a == 3) {
					inclued3 = true;
					break;
				} else {
					inclued3 = false;
				}
				a *= 10;
			}

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

		}
		System.out.println();
	}

} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		boolean inclued3 = false;

		for (int i = 1, a; i <= n; i++) {
			a = 1;
			while (i / a >= 1) {
				if (i % (a * 10) / a == 3) {
					inclued3 = true;
					break;
				} else {
					inclued3 = false;
				}
				a *= 10;
			}

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

		}
		System.out.println();
	} main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		boolean inclued3 = false;

		for (int i = 1, a; i <= n; i++) {
			a = 1;
			while (i / a >= 1) {
				if (i % (a * 10) / a == 3) {
					inclued3 = true;
					break;
				} else {
					inclued3 = false;
				}
				a *= 10;
			}

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

		}
		System.out.println();
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc boolean inclued3 = false; inclued3 false for (int i = 1, a; i <= n; i++) {
			a = 1;
			while (i / a >= 1) {
				if (i % (a * 10) / a == 3) {
					inclued3 = true;
					break;
				} else {
					inclued3 = false;
				}
				a *= 10;
			}

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

		} int i = 1, a; int i = 1 i 1 a; a i <= n i n i++ i++ i {
			a = 1;
			while (i / a >= 1) {
				if (i % (a * 10) / a == 3) {
					inclued3 = true;
					break;
				} else {
					inclued3 = false;
				}
				a *= 10;
			}

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

		} {
			a = 1;
			while (i / a >= 1) {
				if (i % (a * 10) / a == 3) {
					inclued3 = true;
					break;
				} else {
					inclued3 = false;
				}
				a *= 10;
			}

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

		} a = 1 a 1 while (i / a >= 1) {
				if (i % (a * 10) / a == 3) {
					inclued3 = true;
					break;
				} else {
					inclued3 = false;
				}
				a *= 10;
			} i / a >= 1 i / a i a 1 {
				if (i % (a * 10) / a == 3) {
					inclued3 = true;
					break;
				} else {
					inclued3 = false;
				}
				a *= 10;
			} if (i % (a * 10) / a == 3) {
					inclued3 = true;
					break;
				} else {
					inclued3 = false;
				} i % (a * 10) / a == 3 i % (a * 10) / a i % (a * 10) i (a * 10) a 10 a 3 {
					inclued3 = true;
					break;
				} inclued3 = true inclued3 true break; {
					inclued3 = false;
				} inclued3 = false inclued3 false a *= 10 a 10 if (i % 3 == 0 || inclued3) {
				System.out.print(" " + i);
			} i % 3 == 0 || inclued3 i % 3 == 0 i % 3 i 3 0 inclued3 {
				System.out.print(" " + i);
			} System.out.print(" " + i) System.out.print System.out System System.out " " + i " " i 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 n = sc.nextInt();
		boolean inclued3 = false;

		for (int i = 1, a; i <= n; i++) {
			a = 1;
			while (i / a >= 1) {
				if (i % (a * 10) / a == 3) {
					inclued3 = true;
					break;
				} else {
					inclued3 = false;
				}
				a *= 10;
			}

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

		}
		System.out.println();
	}

} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		boolean inclued3 = false;

		for (int i = 1, a; i <= n; i++) {
			a = 1;
			while (i / a >= 1) {
				if (i % (a * 10) / a == 3) {
					inclued3 = true;
					break;
				} else {
					inclued3 = false;
				}
				a *= 10;
			}

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

		}
		System.out.println();
	}

} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		boolean inclued3 = false;

		for (int i = 1, a; i <= n; i++) {
			a = 1;
			while (i / a >= 1) {
				if (i % (a * 10) / a == 3) {
					inclued3 = true;
					break;
				} else {
					inclued3 = false;
				}
				a *= 10;
			}

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

		}
		System.out.println();
	}

}