import java.util.Scanner;

public class Main {
	static void call(int n) {
		int i = 1;
		while (i <= n) {
			if (i % 3 == 0)
				System.out.print(" " + i);
			else if (i % 10 == 3)
				System.out.print(" " + i);
			else if (i / 10 != 0 && (i / 10) % 10 == 3)
				System.out.print(" " + i);
			else if (i / 100 != 0 && (i / 100) % 10 == 3)
				System.out.print(" " + i);
			else if (i / 1000 != 0 && (i / 1000) % 10 == 3)
				System.out.print(" " + i);
			i++;
		}
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int input = sc.nextInt();
		call(input);
		System.out.println();
	}
} import java.util.Scanner; Scanner java.util public class Main {
	static void call(int n) {
		int i = 1;
		while (i <= n) {
			if (i % 3 == 0)
				System.out.print(" " + i);
			else if (i % 10 == 3)
				System.out.print(" " + i);
			else if (i / 10 != 0 && (i / 10) % 10 == 3)
				System.out.print(" " + i);
			else if (i / 100 != 0 && (i / 100) % 10 == 3)
				System.out.print(" " + i);
			else if (i / 1000 != 0 && (i / 1000) % 10 == 3)
				System.out.print(" " + i);
			i++;
		}
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int input = sc.nextInt();
		call(input);
		System.out.println();
	}
} Main static void call(int n) {
		int i = 1;
		while (i <= n) {
			if (i % 3 == 0)
				System.out.print(" " + i);
			else if (i % 10 == 3)
				System.out.print(" " + i);
			else if (i / 10 != 0 && (i / 10) % 10 == 3)
				System.out.print(" " + i);
			else if (i / 100 != 0 && (i / 100) % 10 == 3)
				System.out.print(" " + i);
			else if (i / 1000 != 0 && (i / 1000) % 10 == 3)
				System.out.print(" " + i);
			i++;
		}
	} call {
		int i = 1;
		while (i <= n) {
			if (i % 3 == 0)
				System.out.print(" " + i);
			else if (i % 10 == 3)
				System.out.print(" " + i);
			else if (i / 10 != 0 && (i / 10) % 10 == 3)
				System.out.print(" " + i);
			else if (i / 100 != 0 && (i / 100) % 10 == 3)
				System.out.print(" " + i);
			else if (i / 1000 != 0 && (i / 1000) % 10 == 3)
				System.out.print(" " + i);
			i++;
		}
	} int i = 1; i 1 while (i <= n) {
			if (i % 3 == 0)
				System.out.print(" " + i);
			else if (i % 10 == 3)
				System.out.print(" " + i);
			else if (i / 10 != 0 && (i / 10) % 10 == 3)
				System.out.print(" " + i);
			else if (i / 100 != 0 && (i / 100) % 10 == 3)
				System.out.print(" " + i);
			else if (i / 1000 != 0 && (i / 1000) % 10 == 3)
				System.out.print(" " + i);
			i++;
		} i <= n i n {
			if (i % 3 == 0)
				System.out.print(" " + i);
			else if (i % 10 == 3)
				System.out.print(" " + i);
			else if (i / 10 != 0 && (i / 10) % 10 == 3)
				System.out.print(" " + i);
			else if (i / 100 != 0 && (i / 100) % 10 == 3)
				System.out.print(" " + i);
			else if (i / 1000 != 0 && (i / 1000) % 10 == 3)
				System.out.print(" " + i);
			i++;
		} if (i % 3 == 0)
				System.out.print(" " + i);
			else if (i % 10 == 3)
				System.out.print(" " + i);
			else if (i / 10 != 0 && (i / 10) % 10 == 3)
				System.out.print(" " + i);
			else if (i / 100 != 0 && (i / 100) % 10 == 3)
				System.out.print(" " + i);
			else if (i / 1000 != 0 && (i / 1000) % 10 == 3)
				System.out.print(" " + i); i % 3 == 0 i % 3 i 3 0 System.out.print(" " + i) System.out.print System.out System System.out " " + i " " i if (i % 10 == 3)
				System.out.print(" " + i);
			else if (i / 10 != 0 && (i / 10) % 10 == 3)
				System.out.print(" " + i);
			else if (i / 100 != 0 && (i / 100) % 10 == 3)
				System.out.print(" " + i);
			else if (i / 1000 != 0 && (i / 1000) % 10 == 3)
				System.out.print(" " + i); i % 10 == 3 i % 10 i 10 3 System.out.print(" " + i) System.out.print System.out System System.out " " + i " " i if (i / 10 != 0 && (i / 10) % 10 == 3)
				System.out.print(" " + i);
			else if (i / 100 != 0 && (i / 100) % 10 == 3)
				System.out.print(" " + i);
			else if (i / 1000 != 0 && (i / 1000) % 10 == 3)
				System.out.print(" " + i); i / 10 != 0 && (i / 10) % 10 == 3 i / 10 != 0 i / 10 i 10 0 (i / 10) % 10 == 3 (i / 10) % 10 (i / 10) i 10 10 3 System.out.print(" " + i) System.out.print System.out System System.out " " + i " " i if (i / 100 != 0 && (i / 100) % 10 == 3)
				System.out.print(" " + i);
			else if (i / 1000 != 0 && (i / 1000) % 10 == 3)
				System.out.print(" " + i); i / 100 != 0 && (i / 100) % 10 == 3 i / 100 != 0 i / 100 i 100 0 (i / 100) % 10 == 3 (i / 100) % 10 (i / 100) i 100 10 3 System.out.print(" " + i) System.out.print System.out System System.out " " + i " " i if (i / 1000 != 0 && (i / 1000) % 10 == 3)
				System.out.print(" " + i); i / 1000 != 0 && (i / 1000) % 10 == 3 i / 1000 != 0 i / 1000 i 1000 0 (i / 1000) % 10 == 3 (i / 1000) % 10 (i / 1000) i 1000 10 3 System.out.print(" " + i) System.out.print System.out System System.out " " + i " " i i++ i int n n public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int input = sc.nextInt();
		call(input);
		System.out.println();
	} main {
		Scanner sc = new Scanner(System.in);
		int input = sc.nextInt();
		call(input);
		System.out.println();
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int input = sc.nextInt(); input sc.nextInt() sc.nextInt sc call(input) call input System.out.println() System.out.println System.out System System.out String[] args args public class Main {
	static void call(int n) {
		int i = 1;
		while (i <= n) {
			if (i % 3 == 0)
				System.out.print(" " + i);
			else if (i % 10 == 3)
				System.out.print(" " + i);
			else if (i / 10 != 0 && (i / 10) % 10 == 3)
				System.out.print(" " + i);
			else if (i / 100 != 0 && (i / 100) % 10 == 3)
				System.out.print(" " + i);
			else if (i / 1000 != 0 && (i / 1000) % 10 == 3)
				System.out.print(" " + i);
			i++;
		}
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int input = sc.nextInt();
		call(input);
		System.out.println();
	}
} public class Main {
	static void call(int n) {
		int i = 1;
		while (i <= n) {
			if (i % 3 == 0)
				System.out.print(" " + i);
			else if (i % 10 == 3)
				System.out.print(" " + i);
			else if (i / 10 != 0 && (i / 10) % 10 == 3)
				System.out.print(" " + i);
			else if (i / 100 != 0 && (i / 100) % 10 == 3)
				System.out.print(" " + i);
			else if (i / 1000 != 0 && (i / 1000) % 10 == 3)
				System.out.print(" " + i);
			i++;
		}
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int input = sc.nextInt();
		call(input);
		System.out.println();
	}
} Main
import java.util.Scanner;

public class Main {
	static void call(int n) {
		int i = 1;
		while (i <= n) {
			if (i % 3 == 0)
				System.out.print(" " + i);
			else if (i % 10 == 3)
				System.out.print(" " + i);
			else if (i / 10 != 0 && (i / 10) % 10 == 3)
				System.out.print(" " + i);
			else if (i / 100 != 0 && (i / 100) % 10 == 3)
				System.out.print(" " + i);
			else if (i / 1000 != 0 && (i / 1000) % 10 == 3)
				System.out.print(" " + i);
			i++;
		}
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int input = sc.nextInt();
		call(input);
		System.out.println();
	}
}