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

public class Main {
	public static void main(String[] args) throws Exception {
	
		try{
	BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
    String input = buf.readLine();
//	String[] strAry = input.split(" ");
//    int H = Integer.parseInt(strAry[0]);
//    int W = Integer.parseInt(strAry[1]);
	
int max = Integer.parseInt(input);
int x;

for(int i =3; i <= max; i++){
    x = i;
	if(i%3 == 0){
		System.out.printf(" " + i);
	}else{
	while(x > 1){
		if(x%10 == 3){
		System.out.printf(" " + i);
		break;
	}
		x = x / 10;
	}
	
	}
}
System.out.printf("\n");

} catch (Exception e) {

	System.out.println("????????????");
	
}
		 }
    } import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {
	public static void main(String[] args) throws Exception {
	
		try{
	BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
    String input = buf.readLine();
//	String[] strAry = input.split(" ");
//    int H = Integer.parseInt(strAry[0]);
//    int W = Integer.parseInt(strAry[1]);
	
int max = Integer.parseInt(input);
int x;

for(int i =3; i <= max; i++){
    x = i;
	if(i%3 == 0){
		System.out.printf(" " + i);
	}else{
	while(x > 1){
		if(x%10 == 3){
		System.out.printf(" " + i);
		break;
	}
		x = x / 10;
	}
	
	}
}
System.out.printf("\n");

} catch (Exception e) {

	System.out.println("????????????");
	
}
		 }
    } Main public static void main(String[] args) throws Exception {
	
		try{
	BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
    String input = buf.readLine();
//	String[] strAry = input.split(" ");
//    int H = Integer.parseInt(strAry[0]);
//    int W = Integer.parseInt(strAry[1]);
	
int max = Integer.parseInt(input);
int x;

for(int i =3; i <= max; i++){
    x = i;
	if(i%3 == 0){
		System.out.printf(" " + i);
	}else{
	while(x > 1){
		if(x%10 == 3){
		System.out.printf(" " + i);
		break;
	}
		x = x / 10;
	}
	
	}
}
System.out.printf("\n");

} catch (Exception e) {

	System.out.println("????????????");
	
}
		 } main {
	
		try{
	BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
    String input = buf.readLine();
//	String[] strAry = input.split(" ");
//    int H = Integer.parseInt(strAry[0]);
//    int W = Integer.parseInt(strAry[1]);
	
int max = Integer.parseInt(input);
int x;

for(int i =3; i <= max; i++){
    x = i;
	if(i%3 == 0){
		System.out.printf(" " + i);
	}else{
	while(x > 1){
		if(x%10 == 3){
		System.out.printf(" " + i);
		break;
	}
		x = x / 10;
	}
	
	}
}
System.out.printf("\n");

} catch (Exception e) {

	System.out.println("????????????");
	
}
		 } try{
	BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
    String input = buf.readLine();
//	String[] strAry = input.split(" ");
//    int H = Integer.parseInt(strAry[0]);
//    int W = Integer.parseInt(strAry[1]);
	
int max = Integer.parseInt(input);
int x;

for(int i =3; i <= max; i++){
    x = i;
	if(i%3 == 0){
		System.out.printf(" " + i);
	}else{
	while(x > 1){
		if(x%10 == 3){
		System.out.printf(" " + i);
		break;
	}
		x = x / 10;
	}
	
	}
}
System.out.printf("\n");

} catch (Exception e) {

	System.out.println("????????????");
	
} catch (Exception e) {

	System.out.println("????????????");
	
} Exception e {

	System.out.println("????????????");
	
} System.out.println("????????????") System.out.println System.out System System.out "????????????" {
	BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
    String input = buf.readLine();
//	String[] strAry = input.split(" ");
//    int H = Integer.parseInt(strAry[0]);
//    int W = Integer.parseInt(strAry[1]);
	
int max = Integer.parseInt(input);
int x;

for(int i =3; i <= max; i++){
    x = i;
	if(i%3 == 0){
		System.out.printf(" " + i);
	}else{
	while(x > 1){
		if(x%10 == 3){
		System.out.printf(" " + i);
		break;
	}
		x = x / 10;
	}
	
	}
}
System.out.printf("\n");

} BufferedReader buf = new BufferedReader(new InputStreamReader(System.in)); buf new BufferedReader(new InputStreamReader(System.in)) String input = buf.readLine(); input buf.readLine() buf.readLine buf int max = Integer.parseInt(input); max Integer.parseInt(input) Integer.parseInt Integer input int x; x for(int i =3; i <= max; i++){
    x = i;
	if(i%3 == 0){
		System.out.printf(" " + i);
	}else{
	while(x > 1){
		if(x%10 == 3){
		System.out.printf(" " + i);
		break;
	}
		x = x / 10;
	}
	
	}
} int i =3; int i =3; i 3 i <= max i max i++ i++ i {
    x = i;
	if(i%3 == 0){
		System.out.printf(" " + i);
	}else{
	while(x > 1){
		if(x%10 == 3){
		System.out.printf(" " + i);
		break;
	}
		x = x / 10;
	}
	
	}
} {
    x = i;
	if(i%3 == 0){
		System.out.printf(" " + i);
	}else{
	while(x > 1){
		if(x%10 == 3){
		System.out.printf(" " + i);
		break;
	}
		x = x / 10;
	}
	
	}
} x = i x i if(i%3 == 0){
		System.out.printf(" " + i);
	}else{
	while(x > 1){
		if(x%10 == 3){
		System.out.printf(" " + i);
		break;
	}
		x = 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 {
	while(x > 1){
		if(x%10 == 3){
		System.out.printf(" " + i);
		break;
	}
		x = x / 10;
	}
	
	} while(x > 1){
		if(x%10 == 3){
		System.out.printf(" " + i);
		break;
	}
		x = x / 10;
	} x > 1 x 1 {
		if(x%10 == 3){
		System.out.printf(" " + i);
		break;
	}
		x = x / 10;
	} if(x%10 == 3){
		System.out.printf(" " + i);
		break;
	} 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 = x / 10 x 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) throws Exception {
	
		try{
	BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
    String input = buf.readLine();
//	String[] strAry = input.split(" ");
//    int H = Integer.parseInt(strAry[0]);
//    int W = Integer.parseInt(strAry[1]);
	
int max = Integer.parseInt(input);
int x;

for(int i =3; i <= max; i++){
    x = i;
	if(i%3 == 0){
		System.out.printf(" " + i);
	}else{
	while(x > 1){
		if(x%10 == 3){
		System.out.printf(" " + i);
		break;
	}
		x = x / 10;
	}
	
	}
}
System.out.printf("\n");

} catch (Exception e) {

	System.out.println("????????????");
	
}
		 }
    } public class Main {
	public static void main(String[] args) throws Exception {
	
		try{
	BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
    String input = buf.readLine();
//	String[] strAry = input.split(" ");
//    int H = Integer.parseInt(strAry[0]);
//    int W = Integer.parseInt(strAry[1]);
	
int max = Integer.parseInt(input);
int x;

for(int i =3; i <= max; i++){
    x = i;
	if(i%3 == 0){
		System.out.printf(" " + i);
	}else{
	while(x > 1){
		if(x%10 == 3){
		System.out.printf(" " + i);
		break;
	}
		x = x / 10;
	}
	
	}
}
System.out.printf("\n");

} catch (Exception e) {

	System.out.println("????????????");
	
}
		 }
    } Main
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
	
		try{
	BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
    String input = buf.readLine();
//	String[] strAry = input.split(" ");
//    int H = Integer.parseInt(strAry[0]);
//    int W = Integer.parseInt(strAry[1]);
	
int max = Integer.parseInt(input);
int x;

for(int i =3; i <= max; i++){
    x = i;
	if(i%3 == 0){
		System.out.printf(" " + i);
	}else{
	while(x > 1){
		if(x%10 == 3){
		System.out.printf(" " + i);
		break;
	}
		x = x / 10;
	}
	
	}
}
System.out.printf("\n");

} catch (Exception e) {

	System.out.println("????????????");
	
}
		 }
    }