import java.util.Scanner;
class Main{
public static void main(String[] args){
Scanner scan= new Scanner(System.in);
int b=scan.nextInt();
int[] c;
c =new int[10001];

for(int a=3;a<=b;a++){
int d=a;
if(d%3==0)
	c[a]=1;
else
	c[a]=0;
while(true){
	if(d%10==3){
		
		c[a]=1;
		break;
	}
d=d/10;
if(d==0)
	break;

}
}
for(int i=3;i<=b;i++){
	if(c[i]==1)
		System.out.print(" "+i);
}
System.out.println();
}
} import java.util.Scanner; Scanner java.util class Main{
public static void main(String[] args){
Scanner scan= new Scanner(System.in);
int b=scan.nextInt();
int[] c;
c =new int[10001];

for(int a=3;a<=b;a++){
int d=a;
if(d%3==0)
	c[a]=1;
else
	c[a]=0;
while(true){
	if(d%10==3){
		
		c[a]=1;
		break;
	}
d=d/10;
if(d==0)
	break;

}
}
for(int i=3;i<=b;i++){
	if(c[i]==1)
		System.out.print(" "+i);
}
System.out.println();
}
} Main public static void main(String[] args){
Scanner scan= new Scanner(System.in);
int b=scan.nextInt();
int[] c;
c =new int[10001];

for(int a=3;a<=b;a++){
int d=a;
if(d%3==0)
	c[a]=1;
else
	c[a]=0;
while(true){
	if(d%10==3){
		
		c[a]=1;
		break;
	}
d=d/10;
if(d==0)
	break;

}
}
for(int i=3;i<=b;i++){
	if(c[i]==1)
		System.out.print(" "+i);
}
System.out.println();
} main {
Scanner scan= new Scanner(System.in);
int b=scan.nextInt();
int[] c;
c =new int[10001];

for(int a=3;a<=b;a++){
int d=a;
if(d%3==0)
	c[a]=1;
else
	c[a]=0;
while(true){
	if(d%10==3){
		
		c[a]=1;
		break;
	}
d=d/10;
if(d==0)
	break;

}
}
for(int i=3;i<=b;i++){
	if(c[i]==1)
		System.out.print(" "+i);
}
System.out.println();
} Scanner scan= new Scanner(System.in); scan new Scanner(System.in) int b=scan.nextInt(); b scan.nextInt() scan.nextInt scan int[] c; c c =new int[10001] c new int[10001] 10001 for(int a=3;a<=b;a++){
int d=a;
if(d%3==0)
	c[a]=1;
else
	c[a]=0;
while(true){
	if(d%10==3){
		
		c[a]=1;
		break;
	}
d=d/10;
if(d==0)
	break;

}
} int a=3; int a=3; a 3 a<=b a b a++ a++ a {
int d=a;
if(d%3==0)
	c[a]=1;
else
	c[a]=0;
while(true){
	if(d%10==3){
		
		c[a]=1;
		break;
	}
d=d/10;
if(d==0)
	break;

}
} {
int d=a;
if(d%3==0)
	c[a]=1;
else
	c[a]=0;
while(true){
	if(d%10==3){
		
		c[a]=1;
		break;
	}
d=d/10;
if(d==0)
	break;

}
} int d=a; d a if(d%3==0)
	c[a]=1;
else
	c[a]=0; d%3==0 d%3 d 3 0 c[a]=1 c[a] c a 1 c[a]=0 c[a] c a 0 while(true){
	if(d%10==3){
		
		c[a]=1;
		break;
	}
d=d/10;
if(d==0)
	break;

} true {
	if(d%10==3){
		
		c[a]=1;
		break;
	}
d=d/10;
if(d==0)
	break;

} if(d%10==3){
		
		c[a]=1;
		break;
	} d%10==3 d%10 d 10 3 {
		
		c[a]=1;
		break;
	} c[a]=1 c[a] c a 1 break; d=d/10 d d/10 d 10 if(d==0)
	break; d==0 d 0 break; for(int i=3;i<=b;i++){
	if(c[i]==1)
		System.out.print(" "+i);
} int i=3; int i=3; i 3 i<=b i b i++ i++ i {
	if(c[i]==1)
		System.out.print(" "+i);
} {
	if(c[i]==1)
		System.out.print(" "+i);
} if(c[i]==1)
		System.out.print(" "+i); c[i]==1 c[i] c i 1 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
import java.util.Scanner;
class Main{
public static void main(String[] args){
Scanner scan= new Scanner(System.in);
int b=scan.nextInt();
int[] c;
c =new int[10001];

for(int a=3;a<=b;a++){
int d=a;
if(d%3==0)
	c[a]=1;
else
	c[a]=0;
while(true){
	if(d%10==3){
		
		c[a]=1;
		break;
	}
d=d/10;
if(d==0)
	break;

}
}
for(int i=3;i<=b;i++){
	if(c[i]==1)
		System.out.print(" "+i);
}
System.out.println();
}
}