import java.util.Scanner;

class Main {
	@SuppressWarnings("resource")
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		//?????????
		StringBuilder out = new StringBuilder();
		int n = scan.nextInt();
		
		//??????
		for(int i = 1; i <= n ; i++){
			if(i % 3 == 0){
				out.append(" " + i);
			}//if 
			else {
				int num = i;
				while (num != 0){
					if(num % 10 == 3){
						out.append(" " + i);
						break;
					}else{
						num = num / 10;
					}//else
				}//while
			}//else
		}//for
		//??????
		System.out.println(out);
	}
} import java.util.Scanner; Scanner java.util class Main {
	@SuppressWarnings("resource")
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		//?????????
		StringBuilder out = new StringBuilder();
		int n = scan.nextInt();
		
		//??????
		for(int i = 1; i <= n ; i++){
			if(i % 3 == 0){
				out.append(" " + i);
			}//if 
			else {
				int num = i;
				while (num != 0){
					if(num % 10 == 3){
						out.append(" " + i);
						break;
					}else{
						num = num / 10;
					}//else
				}//while
			}//else
		}//for
		//??????
		System.out.println(out);
	}
} Main @SuppressWarnings("resource")
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		//?????????
		StringBuilder out = new StringBuilder();
		int n = scan.nextInt();
		
		//??????
		for(int i = 1; i <= n ; i++){
			if(i % 3 == 0){
				out.append(" " + i);
			}//if 
			else {
				int num = i;
				while (num != 0){
					if(num % 10 == 3){
						out.append(" " + i);
						break;
					}else{
						num = num / 10;
					}//else
				}//while
			}//else
		}//for
		//??????
		System.out.println(out);
	} main {
		Scanner scan = new Scanner(System.in);
		//?????????
		StringBuilder out = new StringBuilder();
		int n = scan.nextInt();
		
		//??????
		for(int i = 1; i <= n ; i++){
			if(i % 3 == 0){
				out.append(" " + i);
			}//if 
			else {
				int num = i;
				while (num != 0){
					if(num % 10 == 3){
						out.append(" " + i);
						break;
					}else{
						num = num / 10;
					}//else
				}//while
			}//else
		}//for
		//??????
		System.out.println(out);
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) StringBuilder out = new StringBuilder(); out new StringBuilder() int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan for(int i = 1; i <= n ; i++){
			if(i % 3 == 0){
				out.append(" " + i);
			}//if 
			else {
				int num = i;
				while (num != 0){
					if(num % 10 == 3){
						out.append(" " + i);
						break;
					}else{
						num = num / 10;
					}//else
				}//while
			}//else
		}//for int i = 1; int i = 1; i 1 i <= n i n i++ i++ i {
			if(i % 3 == 0){
				out.append(" " + i);
			}//if 
			else {
				int num = i;
				while (num != 0){
					if(num % 10 == 3){
						out.append(" " + i);
						break;
					}else{
						num = num / 10;
					}//else
				}//while
			}//else
		}//for {
			if(i % 3 == 0){
				out.append(" " + i);
			}//if 
			else {
				int num = i;
				while (num != 0){
					if(num % 10 == 3){
						out.append(" " + i);
						break;
					}else{
						num = num / 10;
					}//else
				}//while
			}//else
		} if(i % 3 == 0){
				out.append(" " + i);
			}//if 
			else {
				int num = i;
				while (num != 0){
					if(num % 10 == 3){
						out.append(" " + i);
						break;
					}else{
						num = num / 10;
					}//else
				}//while
			}//else i % 3 == 0 i % 3 i 3 0 {
				out.append(" " + i);
			} out.append(" " + i) out.append out " " + i " " i {
				int num = i;
				while (num != 0){
					if(num % 10 == 3){
						out.append(" " + i);
						break;
					}else{
						num = num / 10;
					}//else
				}//while
			} int num = i; num i while (num != 0){
					if(num % 10 == 3){
						out.append(" " + i);
						break;
					}else{
						num = num / 10;
					}//else
				}//while num != 0 num 0 {
					if(num % 10 == 3){
						out.append(" " + i);
						break;
					}else{
						num = num / 10;
					}//else
				} if(num % 10 == 3){
						out.append(" " + i);
						break;
					}else{
						num = num / 10;
					}//else num % 10 == 3 num % 10 num 10 3 {
						out.append(" " + i);
						break;
					} out.append(" " + i) out.append out " " + i " " i break; {
						num = num / 10;
					} num = num / 10 num num / 10 num 10 System.out.println(out) System.out.println System.out System System.out out String[] args args
import java.util.Scanner;

class Main {
	@SuppressWarnings("resource")
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		//?????????
		StringBuilder out = new StringBuilder();
		int n = scan.nextInt();
		
		//??????
		for(int i = 1; i <= n ; i++){
			if(i % 3 == 0){
				out.append(" " + i);
			}//if 
			else {
				int num = i;
				while (num != 0){
					if(num % 10 == 3){
						out.append(" " + i);
						break;
					}else{
						num = num / 10;
					}//else
				}//while
			}//else
		}//for
		//??????
		System.out.println(out);
	}
}