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


class Main{
	public static void main(String[] args)throws IOException{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String name;
		int num;

		while(true){

			try{
				name=br.readLine();
				num=Integer.parseInt(name);
				nabat(num);
			}

			catch(Exception e){
				System.exit(0);
			}
		}
	}

	public static int nabat(int a){
		int p=a;
		boolean pass=false;
		String nk="";
		int kak=0;

		for(int i=1; i<p+1; i++){
			if(i%3==0 && pass==false){
				System.out.print(" "+i);
				pass=true;
			}
			else if(pass== false){
				nk=i+"";
				kak=nk.indexOf("3");
				if(kak!=-1){
					System.out.print(" "+i);
					pass=true;
				}
			}
			pass=false;
		}
		System.out.println("");
		return 0;
	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io class Main{
	public static void main(String[] args)throws IOException{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String name;
		int num;

		while(true){

			try{
				name=br.readLine();
				num=Integer.parseInt(name);
				nabat(num);
			}

			catch(Exception e){
				System.exit(0);
			}
		}
	}

	public static int nabat(int a){
		int p=a;
		boolean pass=false;
		String nk="";
		int kak=0;

		for(int i=1; i<p+1; i++){
			if(i%3==0 && pass==false){
				System.out.print(" "+i);
				pass=true;
			}
			else if(pass== false){
				nk=i+"";
				kak=nk.indexOf("3");
				if(kak!=-1){
					System.out.print(" "+i);
					pass=true;
				}
			}
			pass=false;
		}
		System.out.println("");
		return 0;
	}
} Main public static void main(String[] args)throws IOException{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String name;
		int num;

		while(true){

			try{
				name=br.readLine();
				num=Integer.parseInt(name);
				nabat(num);
			}

			catch(Exception e){
				System.exit(0);
			}
		}
	} main {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String name;
		int num;

		while(true){

			try{
				name=br.readLine();
				num=Integer.parseInt(name);
				nabat(num);
			}

			catch(Exception e){
				System.exit(0);
			}
		}
	} BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String name; name int num; num while(true){

			try{
				name=br.readLine();
				num=Integer.parseInt(name);
				nabat(num);
			}

			catch(Exception e){
				System.exit(0);
			}
		} true {

			try{
				name=br.readLine();
				num=Integer.parseInt(name);
				nabat(num);
			}

			catch(Exception e){
				System.exit(0);
			}
		} try{
				name=br.readLine();
				num=Integer.parseInt(name);
				nabat(num);
			}

			catch(Exception e){
				System.exit(0);
			} catch(Exception e){
				System.exit(0);
			} Exception e {
				System.exit(0);
			} System.exit(0) System.exit System 0 {
				name=br.readLine();
				num=Integer.parseInt(name);
				nabat(num);
			} name=br.readLine() name br.readLine() br.readLine br num=Integer.parseInt(name) num Integer.parseInt(name) Integer.parseInt Integer name nabat(num) nabat num String[] args args public static int nabat(int a){
		int p=a;
		boolean pass=false;
		String nk="";
		int kak=0;

		for(int i=1; i<p+1; i++){
			if(i%3==0 && pass==false){
				System.out.print(" "+i);
				pass=true;
			}
			else if(pass== false){
				nk=i+"";
				kak=nk.indexOf("3");
				if(kak!=-1){
					System.out.print(" "+i);
					pass=true;
				}
			}
			pass=false;
		}
		System.out.println("");
		return 0;
	} nabat {
		int p=a;
		boolean pass=false;
		String nk="";
		int kak=0;

		for(int i=1; i<p+1; i++){
			if(i%3==0 && pass==false){
				System.out.print(" "+i);
				pass=true;
			}
			else if(pass== false){
				nk=i+"";
				kak=nk.indexOf("3");
				if(kak!=-1){
					System.out.print(" "+i);
					pass=true;
				}
			}
			pass=false;
		}
		System.out.println("");
		return 0;
	} int p=a; p a boolean pass=false; pass false String nk=""; nk "" int kak=0; kak 0 for(int i=1; i<p+1; i++){
			if(i%3==0 && pass==false){
				System.out.print(" "+i);
				pass=true;
			}
			else if(pass== false){
				nk=i+"";
				kak=nk.indexOf("3");
				if(kak!=-1){
					System.out.print(" "+i);
					pass=true;
				}
			}
			pass=false;
		} int i=1; int i=1; i 1 i<p+1 i p+1 p 1 i++ i++ i {
			if(i%3==0 && pass==false){
				System.out.print(" "+i);
				pass=true;
			}
			else if(pass== false){
				nk=i+"";
				kak=nk.indexOf("3");
				if(kak!=-1){
					System.out.print(" "+i);
					pass=true;
				}
			}
			pass=false;
		} {
			if(i%3==0 && pass==false){
				System.out.print(" "+i);
				pass=true;
			}
			else if(pass== false){
				nk=i+"";
				kak=nk.indexOf("3");
				if(kak!=-1){
					System.out.print(" "+i);
					pass=true;
				}
			}
			pass=false;
		} if(i%3==0 && pass==false){
				System.out.print(" "+i);
				pass=true;
			}
			else if(pass== false){
				nk=i+"";
				kak=nk.indexOf("3");
				if(kak!=-1){
					System.out.print(" "+i);
					pass=true;
				}
			} i%3==0 && pass==false i%3==0 i%3 i 3 0 pass==false pass false {
				System.out.print(" "+i);
				pass=true;
			} System.out.print(" "+i) System.out.print System.out System System.out " "+i " " i pass=true pass true if(pass== false){
				nk=i+"";
				kak=nk.indexOf("3");
				if(kak!=-1){
					System.out.print(" "+i);
					pass=true;
				}
			} pass== false pass false {
				nk=i+"";
				kak=nk.indexOf("3");
				if(kak!=-1){
					System.out.print(" "+i);
					pass=true;
				}
			} nk=i+"" nk i+"" i "" kak=nk.indexOf("3") kak nk.indexOf("3") nk.indexOf nk "3" if(kak!=-1){
					System.out.print(" "+i);
					pass=true;
				} kak!=-1 kak -1 1 {
					System.out.print(" "+i);
					pass=true;
				} System.out.print(" "+i) System.out.print System.out System System.out " "+i " " i pass=true pass true pass=false pass false System.out.println("") System.out.println System.out System System.out "" return 0; 0 int a a
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


class Main{
	public static void main(String[] args)throws IOException{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String name;
		int num;

		while(true){

			try{
				name=br.readLine();
				num=Integer.parseInt(name);
				nabat(num);
			}

			catch(Exception e){
				System.exit(0);
			}
		}
	}

	public static int nabat(int a){
		int p=a;
		boolean pass=false;
		String nk="";
		int kak=0;

		for(int i=1; i<p+1; i++){
			if(i%3==0 && pass==false){
				System.out.print(" "+i);
				pass=true;
			}
			else if(pass== false){
				nk=i+"";
				kak=nk.indexOf("3");
				if(kak!=-1){
					System.out.print(" "+i);
					pass=true;
				}
			}
			pass=false;
		}
		System.out.println("");
		return 0;
	}
}