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 i=1;i<=n;i++){
			if(i%3 == 0){
				System.out.printf(" %d",i);
			}else{
				func(i,i);
			}
		}
		System.out.printf("\n");
	}
	
	public static void func(int i,int j){
		if(j%10 == 3){
			System.out.printf(" %d",i);
		}else if(j>0){
			func(i,j/10);
		}
	}

} 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 i=1;i<=n;i++){
			if(i%3 == 0){
				System.out.printf(" %d",i);
			}else{
				func(i,i);
			}
		}
		System.out.printf("\n");
	}
	
	public static void func(int i,int j){
		if(j%10 == 3){
			System.out.printf(" %d",i);
		}else if(j>0){
			func(i,j/10);
		}
	}

} Main public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for(int i=1;i<=n;i++){
			if(i%3 == 0){
				System.out.printf(" %d",i);
			}else{
				func(i,i);
			}
		}
		System.out.printf("\n");
	} main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for(int i=1;i<=n;i++){
			if(i%3 == 0){
				System.out.printf(" %d",i);
			}else{
				func(i,i);
			}
		}
		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 i=1;i<=n;i++){
			if(i%3 == 0){
				System.out.printf(" %d",i);
			}else{
				func(i,i);
			}
		} int i=1; int i=1; i 1 i<=n i n i++ i++ i {
			if(i%3 == 0){
				System.out.printf(" %d",i);
			}else{
				func(i,i);
			}
		} {
			if(i%3 == 0){
				System.out.printf(" %d",i);
			}else{
				func(i,i);
			}
		} if(i%3 == 0){
				System.out.printf(" %d",i);
			}else{
				func(i,i);
			} i%3 == 0 i%3 i 3 0 {
				System.out.printf(" %d",i);
			} System.out.printf(" %d",i) System.out.printf System.out System System.out " %d" i {
				func(i,i);
			} func(i,i) func i i System.out.printf("\n") System.out.printf System.out System System.out "\n" String[] args args public static void func(int i,int j){
		if(j%10 == 3){
			System.out.printf(" %d",i);
		}else if(j>0){
			func(i,j/10);
		}
	} func {
		if(j%10 == 3){
			System.out.printf(" %d",i);
		}else if(j>0){
			func(i,j/10);
		}
	} if(j%10 == 3){
			System.out.printf(" %d",i);
		}else if(j>0){
			func(i,j/10);
		} j%10 == 3 j%10 j 10 3 {
			System.out.printf(" %d",i);
		} System.out.printf(" %d",i) System.out.printf System.out System System.out " %d" i if(j>0){
			func(i,j/10);
		} j>0 j 0 {
			func(i,j/10);
		} func(i,j/10) func i j/10 j 10 int i i int j j public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for(int i=1;i<=n;i++){
			if(i%3 == 0){
				System.out.printf(" %d",i);
			}else{
				func(i,i);
			}
		}
		System.out.printf("\n");
	}
	
	public static void func(int i,int j){
		if(j%10 == 3){
			System.out.printf(" %d",i);
		}else if(j>0){
			func(i,j/10);
		}
	}

} public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for(int i=1;i<=n;i++){
			if(i%3 == 0){
				System.out.printf(" %d",i);
			}else{
				func(i,i);
			}
		}
		System.out.printf("\n");
	}
	
	public static void func(int i,int j){
		if(j%10 == 3){
			System.out.printf(" %d",i);
		}else if(j>0){
			func(i,j/10);
		}
	}

} 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 i=1;i<=n;i++){
			if(i%3 == 0){
				System.out.printf(" %d",i);
			}else{
				func(i,i);
			}
		}
		System.out.printf("\n");
	}
	
	public static void func(int i,int j){
		if(j%10 == 3){
			System.out.printf(" %d",i);
		}else if(j>0){
			func(i,j/10);
		}
	}

}