import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for (int k = 3; k <= n; k++) {
			String s = String.valueOf(k);
			if (k % 3 == 0 || s.indexOf("3") >= 0) {
				System.out.printf(" " + k);
			}

		}
		System.out.printf("\n");
	}
} 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();
		for (int k = 3; k <= n; k++) {
			String s = String.valueOf(k);
			if (k % 3 == 0 || s.indexOf("3") >= 0) {
				System.out.printf(" " + k);
			}

		}
		System.out.printf("\n");
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for (int k = 3; k <= n; k++) {
			String s = String.valueOf(k);
			if (k % 3 == 0 || s.indexOf("3") >= 0) {
				System.out.printf(" " + k);
			}

		}
		System.out.printf("\n");
	} main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for (int k = 3; k <= n; k++) {
			String s = String.valueOf(k);
			if (k % 3 == 0 || s.indexOf("3") >= 0) {
				System.out.printf(" " + k);
			}

		}
		System.out.printf("\n");
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc for (int k = 3; k <= n; k++) {
			String s = String.valueOf(k);
			if (k % 3 == 0 || s.indexOf("3") >= 0) {
				System.out.printf(" " + k);
			}

		} int k = 3; int k = 3; k 3 k <= n k n k++ k++ k {
			String s = String.valueOf(k);
			if (k % 3 == 0 || s.indexOf("3") >= 0) {
				System.out.printf(" " + k);
			}

		} {
			String s = String.valueOf(k);
			if (k % 3 == 0 || s.indexOf("3") >= 0) {
				System.out.printf(" " + k);
			}

		} String s = String.valueOf(k); s String.valueOf(k) String.valueOf String k if (k % 3 == 0 || s.indexOf("3") >= 0) {
				System.out.printf(" " + k);
			} k % 3 == 0 || s.indexOf("3") >= 0 k % 3 == 0 k % 3 k 3 0 s.indexOf("3") >= 0 s.indexOf("3") s.indexOf s "3" 0 {
				System.out.printf(" " + k);
			} System.out.printf(" " + k) System.out.printf System.out System System.out " " + k " " k System.out.printf("\n") System.out.printf System.out System System.out "\n" String[] args args public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for (int k = 3; k <= n; k++) {
			String s = String.valueOf(k);
			if (k % 3 == 0 || s.indexOf("3") >= 0) {
				System.out.printf(" " + k);
			}

		}
		System.out.printf("\n");
	}
} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for (int k = 3; k <= n; k++) {
			String s = String.valueOf(k);
			if (k % 3 == 0 || s.indexOf("3") >= 0) {
				System.out.printf(" " + k);
			}

		}
		System.out.printf("\n");
	}
} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for (int k = 3; k <= n; k++) {
			String s = String.valueOf(k);
			if (k % 3 == 0 || s.indexOf("3") >= 0) {
				System.out.printf(" " + k);
			}

		}
		System.out.printf("\n");
	}
}