import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int a=Integer.parseInt(br.readLine());
		for(int i=3;i<=a;i++){int b=0;
		if(i%3==0)System.out.print(" "+i);
		else if(i/1000==3)System.out.print(" "+i);
		else if((b=i%1000)/100==3)System.out.print(" "+i);
		else if((b=b%100)/10==3)System.out.print(" "+i);
		else if(b%10==3)System.out.print(" "+i);
					
		}System.out.println();
}} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int a=Integer.parseInt(br.readLine());
		for(int i=3;i<=a;i++){int b=0;
		if(i%3==0)System.out.print(" "+i);
		else if(i/1000==3)System.out.print(" "+i);
		else if((b=i%1000)/100==3)System.out.print(" "+i);
		else if((b=b%100)/10==3)System.out.print(" "+i);
		else if(b%10==3)System.out.print(" "+i);
					
		}System.out.println();
}} Main public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int a=Integer.parseInt(br.readLine());
		for(int i=3;i<=a;i++){int b=0;
		if(i%3==0)System.out.print(" "+i);
		else if(i/1000==3)System.out.print(" "+i);
		else if((b=i%1000)/100==3)System.out.print(" "+i);
		else if((b=b%100)/10==3)System.out.print(" "+i);
		else if(b%10==3)System.out.print(" "+i);
					
		}System.out.println();
} main {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int a=Integer.parseInt(br.readLine());
		for(int i=3;i<=a;i++){int b=0;
		if(i%3==0)System.out.print(" "+i);
		else if(i/1000==3)System.out.print(" "+i);
		else if((b=i%1000)/100==3)System.out.print(" "+i);
		else if((b=b%100)/10==3)System.out.print(" "+i);
		else if(b%10==3)System.out.print(" "+i);
					
		}System.out.println();
} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) int a=Integer.parseInt(br.readLine()); a Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br for(int i=3;i<=a;i++){int b=0;
		if(i%3==0)System.out.print(" "+i);
		else if(i/1000==3)System.out.print(" "+i);
		else if((b=i%1000)/100==3)System.out.print(" "+i);
		else if((b=b%100)/10==3)System.out.print(" "+i);
		else if(b%10==3)System.out.print(" "+i);
					
		} int i=3; int i=3; i 3 i<=a i a i++ i++ i {int b=0;
		if(i%3==0)System.out.print(" "+i);
		else if(i/1000==3)System.out.print(" "+i);
		else if((b=i%1000)/100==3)System.out.print(" "+i);
		else if((b=b%100)/10==3)System.out.print(" "+i);
		else if(b%10==3)System.out.print(" "+i);
					
		} {int b=0;
		if(i%3==0)System.out.print(" "+i);
		else if(i/1000==3)System.out.print(" "+i);
		else if((b=i%1000)/100==3)System.out.print(" "+i);
		else if((b=b%100)/10==3)System.out.print(" "+i);
		else if(b%10==3)System.out.print(" "+i);
					
		} int b=0; b 0 if(i%3==0)System.out.print(" "+i);
		else if(i/1000==3)System.out.print(" "+i);
		else if((b=i%1000)/100==3)System.out.print(" "+i);
		else if((b=b%100)/10==3)System.out.print(" "+i);
		else if(b%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/1000==3)System.out.print(" "+i);
		else if((b=i%1000)/100==3)System.out.print(" "+i);
		else if((b=b%100)/10==3)System.out.print(" "+i);
		else if(b%10==3)System.out.print(" "+i); i/1000==3 i/1000 i 1000 3 System.out.print(" "+i) System.out.print System.out System System.out " "+i " " i if((b=i%1000)/100==3)System.out.print(" "+i);
		else if((b=b%100)/10==3)System.out.print(" "+i);
		else if(b%10==3)System.out.print(" "+i); (b=i%1000)/100==3 (b=i%1000)/100 (b=i%1000) b i%1000 i 1000 100 3 System.out.print(" "+i) System.out.print System.out System System.out " "+i " " i if((b=b%100)/10==3)System.out.print(" "+i);
		else if(b%10==3)System.out.print(" "+i); (b=b%100)/10==3 (b=b%100)/10 (b=b%100) b b%100 b 100 10 3 System.out.print(" "+i) System.out.print System.out System System.out " "+i " " i if(b%10==3)System.out.print(" "+i); b%10==3 b%10 b 10 3 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) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int a=Integer.parseInt(br.readLine());
		for(int i=3;i<=a;i++){int b=0;
		if(i%3==0)System.out.print(" "+i);
		else if(i/1000==3)System.out.print(" "+i);
		else if((b=i%1000)/100==3)System.out.print(" "+i);
		else if((b=b%100)/10==3)System.out.print(" "+i);
		else if(b%10==3)System.out.print(" "+i);
					
		}System.out.println();
}} public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int a=Integer.parseInt(br.readLine());
		for(int i=3;i<=a;i++){int b=0;
		if(i%3==0)System.out.print(" "+i);
		else if(i/1000==3)System.out.print(" "+i);
		else if((b=i%1000)/100==3)System.out.print(" "+i);
		else if((b=b%100)/10==3)System.out.print(" "+i);
		else if(b%10==3)System.out.print(" "+i);
					
		}System.out.println();
}} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int a=Integer.parseInt(br.readLine());
		for(int i=3;i<=a;i++){int b=0;
		if(i%3==0)System.out.print(" "+i);
		else if(i/1000==3)System.out.print(" "+i);
		else if((b=i%1000)/100==3)System.out.print(" "+i);
		else if((b=b%100)/10==3)System.out.print(" "+i);
		else if(b%10==3)System.out.print(" "+i);
					
		}System.out.println();
}}