import java.util.Scanner;
class Main {
	public void kami() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		if(3 <= n && n <= 10000){
			for(int i = 3; i <= n; i++){
				int x = i % 3;
				int y = i % 10;
				int anko = i / 10;
				int inko = i / 10 % 10;
				int unko = i / 100;
				int enko = i / 100 % 10;
				int onko = i / 1000;
				
				if(x == 0){
					System.out.print(" " + i);
				}else if(y == 3 || anko == 3 || inko == 3 || unko == 3 || enko == 3 || onko == 3){
					System.out.print(" " + i);
				}
			}
			System.out.println();
		}
		
	}

	public static void main(String[] args) {

		new Main().kami();
	}

} import java.util.Scanner; Scanner java.util class Main {
	public void kami() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		if(3 <= n && n <= 10000){
			for(int i = 3; i <= n; i++){
				int x = i % 3;
				int y = i % 10;
				int anko = i / 10;
				int inko = i / 10 % 10;
				int unko = i / 100;
				int enko = i / 100 % 10;
				int onko = i / 1000;
				
				if(x == 0){
					System.out.print(" " + i);
				}else if(y == 3 || anko == 3 || inko == 3 || unko == 3 || enko == 3 || onko == 3){
					System.out.print(" " + i);
				}
			}
			System.out.println();
		}
		
	}

	public static void main(String[] args) {

		new Main().kami();
	}

} Main public void kami() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		if(3 <= n && n <= 10000){
			for(int i = 3; i <= n; i++){
				int x = i % 3;
				int y = i % 10;
				int anko = i / 10;
				int inko = i / 10 % 10;
				int unko = i / 100;
				int enko = i / 100 % 10;
				int onko = i / 1000;
				
				if(x == 0){
					System.out.print(" " + i);
				}else if(y == 3 || anko == 3 || inko == 3 || unko == 3 || enko == 3 || onko == 3){
					System.out.print(" " + i);
				}
			}
			System.out.println();
		}
		
	} kami {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		if(3 <= n && n <= 10000){
			for(int i = 3; i <= n; i++){
				int x = i % 3;
				int y = i % 10;
				int anko = i / 10;
				int inko = i / 10 % 10;
				int unko = i / 100;
				int enko = i / 100 % 10;
				int onko = i / 1000;
				
				if(x == 0){
					System.out.print(" " + i);
				}else if(y == 3 || anko == 3 || inko == 3 || unko == 3 || enko == 3 || onko == 3){
					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 if(3 <= n && n <= 10000){
			for(int i = 3; i <= n; i++){
				int x = i % 3;
				int y = i % 10;
				int anko = i / 10;
				int inko = i / 10 % 10;
				int unko = i / 100;
				int enko = i / 100 % 10;
				int onko = i / 1000;
				
				if(x == 0){
					System.out.print(" " + i);
				}else if(y == 3 || anko == 3 || inko == 3 || unko == 3 || enko == 3 || onko == 3){
					System.out.print(" " + i);
				}
			}
			System.out.println();
		} 3 <= n && n <= 10000 3 <= n 3 n n <= 10000 n 10000 {
			for(int i = 3; i <= n; i++){
				int x = i % 3;
				int y = i % 10;
				int anko = i / 10;
				int inko = i / 10 % 10;
				int unko = i / 100;
				int enko = i / 100 % 10;
				int onko = i / 1000;
				
				if(x == 0){
					System.out.print(" " + i);
				}else if(y == 3 || anko == 3 || inko == 3 || unko == 3 || enko == 3 || onko == 3){
					System.out.print(" " + i);
				}
			}
			System.out.println();
		} for(int i = 3; i <= n; i++){
				int x = i % 3;
				int y = i % 10;
				int anko = i / 10;
				int inko = i / 10 % 10;
				int unko = i / 100;
				int enko = i / 100 % 10;
				int onko = i / 1000;
				
				if(x == 0){
					System.out.print(" " + i);
				}else if(y == 3 || anko == 3 || inko == 3 || unko == 3 || enko == 3 || onko == 3){
					System.out.print(" " + i);
				}
			} int i = 3; int i = 3; i 3 i <= n i n i++ i++ i {
				int x = i % 3;
				int y = i % 10;
				int anko = i / 10;
				int inko = i / 10 % 10;
				int unko = i / 100;
				int enko = i / 100 % 10;
				int onko = i / 1000;
				
				if(x == 0){
					System.out.print(" " + i);
				}else if(y == 3 || anko == 3 || inko == 3 || unko == 3 || enko == 3 || onko == 3){
					System.out.print(" " + i);
				}
			} {
				int x = i % 3;
				int y = i % 10;
				int anko = i / 10;
				int inko = i / 10 % 10;
				int unko = i / 100;
				int enko = i / 100 % 10;
				int onko = i / 1000;
				
				if(x == 0){
					System.out.print(" " + i);
				}else if(y == 3 || anko == 3 || inko == 3 || unko == 3 || enko == 3 || onko == 3){
					System.out.print(" " + i);
				}
			} int x = i % 3; x i % 3 i 3 int y = i % 10; y i % 10 i 10 int anko = i / 10; anko i / 10 i 10 int inko = i / 10 % 10; inko i / 10 % 10 i / 10 i 10 10 int unko = i / 100; unko i / 100 i 100 int enko = i / 100 % 10; enko i / 100 % 10 i / 100 i 100 10 int onko = i / 1000; onko i / 1000 i 1000 if(x == 0){
					System.out.print(" " + i);
				}else if(y == 3 || anko == 3 || inko == 3 || unko == 3 || enko == 3 || onko == 3){
					System.out.print(" " + i);
				} x == 0 x 0 {
					System.out.print(" " + i);
				} System.out.print(" " + i) System.out.print System.out System System.out " " + i " " i if(y == 3 || anko == 3 || inko == 3 || unko == 3 || enko == 3 || onko == 3){
					System.out.print(" " + i);
				} y == 3 || anko == 3 || inko == 3 || unko == 3 || enko == 3 || onko == 3 enko == 3 unko == 3 inko == 3 y == 3 || anko == 3 || inko == 3 || unko == 3 || enko == 3 || onko == 3 y == 3 y 3 anko == 3 anko 3 inko == 3 inko 3 unko == 3 unko 3 enko == 3 enko 3 onko == 3 onko 3 {
					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 public static void main(String[] args) {

		new Main().kami();
	} main {

		new Main().kami();
	} new Main().kami() new Main().kami new Main() String[] args args
import java.util.Scanner;
class Main {
	public void kami() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		if(3 <= n && n <= 10000){
			for(int i = 3; i <= n; i++){
				int x = i % 3;
				int y = i % 10;
				int anko = i / 10;
				int inko = i / 10 % 10;
				int unko = i / 100;
				int enko = i / 100 % 10;
				int onko = i / 1000;
				
				if(x == 0){
					System.out.print(" " + i);
				}else if(y == 3 || anko == 3 || inko == 3 || unko == 3 || enko == 3 || onko == 3){
					System.out.print(" " + i);
				}
			}
			System.out.println();
		}
		
	}

	public static void main(String[] args) {

		new Main().kami();
	}

}