	import java.util.Scanner;
	public class Main {
	public static void main(String[] args) {
	Scanner sc= new Scanner(System.in);
	//while(true) {
	int a = sc.nextInt();
	int i;
	//if (a == 0) {
	//break;
	
	for(i=3;i<=a;i++){int j=i;
		if(j%3==0){System.out.printf(" "+i);
		
		}else{
		while(j!=0){if(j%10==3){System.out.printf(" "+i);break;}
		
		j/=10;}
		}}
	System.out.println();
	
	}}
	
	 import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
	Scanner sc= new Scanner(System.in);
	//while(true) {
	int a = sc.nextInt();
	int i;
	//if (a == 0) {
	//break;
	
	for(i=3;i<=a;i++){int j=i;
		if(j%3==0){System.out.printf(" "+i);
		
		}else{
		while(j!=0){if(j%10==3){System.out.printf(" "+i);break;}
		
		j/=10;}
		}}
	System.out.println();
	
	}} Main public static void main(String[] args) {
	Scanner sc= new Scanner(System.in);
	//while(true) {
	int a = sc.nextInt();
	int i;
	//if (a == 0) {
	//break;
	
	for(i=3;i<=a;i++){int j=i;
		if(j%3==0){System.out.printf(" "+i);
		
		}else{
		while(j!=0){if(j%10==3){System.out.printf(" "+i);break;}
		
		j/=10;}
		}}
	System.out.println();
	
	} main {
	Scanner sc= new Scanner(System.in);
	//while(true) {
	int a = sc.nextInt();
	int i;
	//if (a == 0) {
	//break;
	
	for(i=3;i<=a;i++){int j=i;
		if(j%3==0){System.out.printf(" "+i);
		
		}else{
		while(j!=0){if(j%10==3){System.out.printf(" "+i);break;}
		
		j/=10;}
		}}
	System.out.println();
	
	} Scanner sc= new Scanner(System.in); sc new Scanner(System.in) int a = sc.nextInt(); a sc.nextInt() sc.nextInt sc int i; i for(i=3;i<=a;i++){int j=i;
		if(j%3==0){System.out.printf(" "+i);
		
		}else{
		while(j!=0){if(j%10==3){System.out.printf(" "+i);break;}
		
		j/=10;}
		}} i=3; i=3 i 3 i<=a i a i++ i++ i {int j=i;
		if(j%3==0){System.out.printf(" "+i);
		
		}else{
		while(j!=0){if(j%10==3){System.out.printf(" "+i);break;}
		
		j/=10;}
		}} {int j=i;
		if(j%3==0){System.out.printf(" "+i);
		
		}else{
		while(j!=0){if(j%10==3){System.out.printf(" "+i);break;}
		
		j/=10;}
		}} int j=i; j i if(j%3==0){System.out.printf(" "+i);
		
		}else{
		while(j!=0){if(j%10==3){System.out.printf(" "+i);break;}
		
		j/=10;}
		} j%3==0 j%3 j 3 0 {System.out.printf(" "+i);
		
		} System.out.printf(" "+i) System.out.printf System.out System System.out " "+i " " i {
		while(j!=0){if(j%10==3){System.out.printf(" "+i);break;}
		
		j/=10;}
		} while(j!=0){if(j%10==3){System.out.printf(" "+i);break;}
		
		j/=10;} j!=0 j 0 {if(j%10==3){System.out.printf(" "+i);break;}
		
		j/=10;} if(j%10==3){System.out.printf(" "+i);break;} j%10==3 j%10 j 10 3 {System.out.printf(" "+i);break;} System.out.printf(" "+i) System.out.printf System.out System System.out " "+i " " i break; j/=10 j 10 System.out.println() System.out.println System.out System System.out String[] args args public class Main {
	public static void main(String[] args) {
	Scanner sc= new Scanner(System.in);
	//while(true) {
	int a = sc.nextInt();
	int i;
	//if (a == 0) {
	//break;
	
	for(i=3;i<=a;i++){int j=i;
		if(j%3==0){System.out.printf(" "+i);
		
		}else{
		while(j!=0){if(j%10==3){System.out.printf(" "+i);break;}
		
		j/=10;}
		}}
	System.out.println();
	
	}} public class Main {
	public static void main(String[] args) {
	Scanner sc= new Scanner(System.in);
	//while(true) {
	int a = sc.nextInt();
	int i;
	//if (a == 0) {
	//break;
	
	for(i=3;i<=a;i++){int j=i;
		if(j%3==0){System.out.printf(" "+i);
		
		}else{
		while(j!=0){if(j%10==3){System.out.printf(" "+i);break;}
		
		j/=10;}
		}}
	System.out.println();
	
	}} Main
	import java.util.Scanner;
	public class Main {
	public static void main(String[] args) {
	Scanner sc= new Scanner(System.in);
	//while(true) {
	int a = sc.nextInt();
	int i;
	//if (a == 0) {
	//break;
	
	for(i=3;i<=a;i++){int j=i;
		if(j%3==0){System.out.printf(" "+i);
		
		}else{
		while(j!=0){if(j%10==3){System.out.printf(" "+i);break;}
		
		j/=10;}
		}}
	System.out.println();
	
	}}
	
	