import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
	Scanner sc= new Scanner(System.in);
	int n = sc.nextInt();
	int i= 1;
	 while (++i <= n){
		 if(i % 3 == 0){
			 System.out.printf(" "+ i);
		 }else if(i % 10 == 3){
			 System.out.printf(" "+ i); 
		 }else{
			 int x = i / 10;
			 while(x != 0){
				 if(x % 10 == 3){
					 System.out.printf(" "+ i);
					 break;
				 }else{
					 x /= 10;
			 }
			 }
		 }
	 }
	 System.out.printf("\n"); 
	}
} 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();
	int i= 1;
	 while (++i <= n){
		 if(i % 3 == 0){
			 System.out.printf(" "+ i);
		 }else if(i % 10 == 3){
			 System.out.printf(" "+ i); 
		 }else{
			 int x = i / 10;
			 while(x != 0){
				 if(x % 10 == 3){
					 System.out.printf(" "+ i);
					 break;
				 }else{
					 x /= 10;
			 }
			 }
		 }
	 }
	 System.out.printf("\n"); 
	}
} Main public static void main(String[] args) {
	Scanner sc= new Scanner(System.in);
	int n = sc.nextInt();
	int i= 1;
	 while (++i <= n){
		 if(i % 3 == 0){
			 System.out.printf(" "+ i);
		 }else if(i % 10 == 3){
			 System.out.printf(" "+ i); 
		 }else{
			 int x = i / 10;
			 while(x != 0){
				 if(x % 10 == 3){
					 System.out.printf(" "+ i);
					 break;
				 }else{
					 x /= 10;
			 }
			 }
		 }
	 }
	 System.out.printf("\n"); 
	} main {
	Scanner sc= new Scanner(System.in);
	int n = sc.nextInt();
	int i= 1;
	 while (++i <= n){
		 if(i % 3 == 0){
			 System.out.printf(" "+ i);
		 }else if(i % 10 == 3){
			 System.out.printf(" "+ i); 
		 }else{
			 int x = i / 10;
			 while(x != 0){
				 if(x % 10 == 3){
					 System.out.printf(" "+ i);
					 break;
				 }else{
					 x /= 10;
			 }
			 }
		 }
	 }
	 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 int i= 1; i 1 while (++i <= n){
		 if(i % 3 == 0){
			 System.out.printf(" "+ i);
		 }else if(i % 10 == 3){
			 System.out.printf(" "+ i); 
		 }else{
			 int x = i / 10;
			 while(x != 0){
				 if(x % 10 == 3){
					 System.out.printf(" "+ i);
					 break;
				 }else{
					 x /= 10;
			 }
			 }
		 }
	 } ++i <= n ++i i n {
		 if(i % 3 == 0){
			 System.out.printf(" "+ i);
		 }else if(i % 10 == 3){
			 System.out.printf(" "+ i); 
		 }else{
			 int x = i / 10;
			 while(x != 0){
				 if(x % 10 == 3){
					 System.out.printf(" "+ i);
					 break;
				 }else{
					 x /= 10;
			 }
			 }
		 }
	 } if(i % 3 == 0){
			 System.out.printf(" "+ i);
		 }else if(i % 10 == 3){
			 System.out.printf(" "+ i); 
		 }else{
			 int x = i / 10;
			 while(x != 0){
				 if(x % 10 == 3){
					 System.out.printf(" "+ i);
					 break;
				 }else{
					 x /= 10;
			 }
			 }
		 } i % 3 == 0 i % 3 i 3 0 {
			 System.out.printf(" "+ i);
		 } System.out.printf(" "+ i) System.out.printf System.out System System.out " "+ i " " i if(i % 10 == 3){
			 System.out.printf(" "+ i); 
		 }else{
			 int x = i / 10;
			 while(x != 0){
				 if(x % 10 == 3){
					 System.out.printf(" "+ i);
					 break;
				 }else{
					 x /= 10;
			 }
			 }
		 } i % 10 == 3 i % 10 i 10 3 {
			 System.out.printf(" "+ i); 
		 } System.out.printf(" "+ i) System.out.printf System.out System System.out " "+ i " " i {
			 int x = i / 10;
			 while(x != 0){
				 if(x % 10 == 3){
					 System.out.printf(" "+ i);
					 break;
				 }else{
					 x /= 10;
			 }
			 }
		 } int x = i / 10; x i / 10 i 10 while(x != 0){
				 if(x % 10 == 3){
					 System.out.printf(" "+ i);
					 break;
				 }else{
					 x /= 10;
			 }
			 } x != 0 x 0 {
				 if(x % 10 == 3){
					 System.out.printf(" "+ i);
					 break;
				 }else{
					 x /= 10;
			 }
			 } if(x % 10 == 3){
					 System.out.printf(" "+ i);
					 break;
				 }else{
					 x /= 10;
			 } x % 10 == 3 x % 10 x 10 3 {
					 System.out.printf(" "+ i);
					 break;
				 } System.out.printf(" "+ i) System.out.printf System.out System System.out " "+ i " " i break; {
					 x /= 10;
			 } x /= 10 x 10 System.out.printf("\n") System.out.printf System.out System System.out "\n" String[] args args public class Main {
	public static void main(String[] args) {
	Scanner sc= new Scanner(System.in);
	int n = sc.nextInt();
	int i= 1;
	 while (++i <= n){
		 if(i % 3 == 0){
			 System.out.printf(" "+ i);
		 }else if(i % 10 == 3){
			 System.out.printf(" "+ i); 
		 }else{
			 int x = i / 10;
			 while(x != 0){
				 if(x % 10 == 3){
					 System.out.printf(" "+ i);
					 break;
				 }else{
					 x /= 10;
			 }
			 }
		 }
	 }
	 System.out.printf("\n"); 
	}
} public class Main {
	public static void main(String[] args) {
	Scanner sc= new Scanner(System.in);
	int n = sc.nextInt();
	int i= 1;
	 while (++i <= n){
		 if(i % 3 == 0){
			 System.out.printf(" "+ i);
		 }else if(i % 10 == 3){
			 System.out.printf(" "+ i); 
		 }else{
			 int x = i / 10;
			 while(x != 0){
				 if(x % 10 == 3){
					 System.out.printf(" "+ i);
					 break;
				 }else{
					 x /= 10;
			 }
			 }
		 }
	 }
	 System.out.printf("\n"); 
	}
} Main
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
	Scanner sc= new Scanner(System.in);
	int n = sc.nextInt();
	int i= 1;
	 while (++i <= n){
		 if(i % 3 == 0){
			 System.out.printf(" "+ i);
		 }else if(i % 10 == 3){
			 System.out.printf(" "+ i); 
		 }else{
			 int x = i / 10;
			 while(x != 0){
				 if(x % 10 == 3){
					 System.out.printf(" "+ i);
					 break;
				 }else{
					 x /= 10;
			 }
			 }
		 }
	 }
	 System.out.printf("\n"); 
	}
}