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

public class Main {
	static int n;

	public static void main(String[] args) throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        n = Integer.parseInt(br.readLine());
        for(int i = 1; i <= n; i++){
        	if(CHECK_NUM(i)) continue;
        	INCLUDE_3(i);
        }
        System.out.println();
	}

	public static boolean CHECK_NUM(int x){
		if ( x % 3 == 0 ){
			System.out.print(" " + x);
			return true;
		}else{
			return false;
		}
	}

	public static void INCLUDE_3(int i){
		int x = i;
		while(x != 0){
			if ( x % 10 == 3 ){
				System.out.print(" " + i);
				break;
			}
			x /= 10;
		}
	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {
	static int n;

	public static void main(String[] args) throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        n = Integer.parseInt(br.readLine());
        for(int i = 1; i <= n; i++){
        	if(CHECK_NUM(i)) continue;
        	INCLUDE_3(i);
        }
        System.out.println();
	}

	public static boolean CHECK_NUM(int x){
		if ( x % 3 == 0 ){
			System.out.print(" " + x);
			return true;
		}else{
			return false;
		}
	}

	public static void INCLUDE_3(int i){
		int x = i;
		while(x != 0){
			if ( x % 10 == 3 ){
				System.out.print(" " + i);
				break;
			}
			x /= 10;
		}
	}
} Main static int n; n public static void main(String[] args) throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        n = Integer.parseInt(br.readLine());
        for(int i = 1; i <= n; i++){
        	if(CHECK_NUM(i)) continue;
        	INCLUDE_3(i);
        }
        System.out.println();
	} main {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        n = Integer.parseInt(br.readLine());
        for(int i = 1; i <= n; i++){
        	if(CHECK_NUM(i)) continue;
        	INCLUDE_3(i);
        }
        System.out.println();
	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) n = Integer.parseInt(br.readLine()) n Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br for(int i = 1; i <= n; i++){
        	if(CHECK_NUM(i)) continue;
        	INCLUDE_3(i);
        } int i = 1; int i = 1; i 1 i <= n i n i++ i++ i {
        	if(CHECK_NUM(i)) continue;
        	INCLUDE_3(i);
        } {
        	if(CHECK_NUM(i)) continue;
        	INCLUDE_3(i);
        } if(CHECK_NUM(i)) continue; CHECK_NUM(i) CHECK_NUM i continue; INCLUDE_3(i) INCLUDE_3 i System.out.println() System.out.println System.out System System.out String[] args args public static boolean CHECK_NUM(int x){
		if ( x % 3 == 0 ){
			System.out.print(" " + x);
			return true;
		}else{
			return false;
		}
	} CHECK_NUM {
		if ( x % 3 == 0 ){
			System.out.print(" " + x);
			return true;
		}else{
			return false;
		}
	} if ( x % 3 == 0 ){
			System.out.print(" " + x);
			return true;
		}else{
			return false;
		} x % 3 == 0 x % 3 x 3 0 {
			System.out.print(" " + x);
			return true;
		} System.out.print(" " + x) System.out.print System.out System System.out " " + x " " x return true; true {
			return false;
		} return false; false int x x public static void INCLUDE_3(int i){
		int x = i;
		while(x != 0){
			if ( x % 10 == 3 ){
				System.out.print(" " + i);
				break;
			}
			x /= 10;
		}
	} INCLUDE_3 {
		int x = i;
		while(x != 0){
			if ( x % 10 == 3 ){
				System.out.print(" " + i);
				break;
			}
			x /= 10;
		}
	} int x = i; x i while(x != 0){
			if ( x % 10 == 3 ){
				System.out.print(" " + i);
				break;
			}
			x /= 10;
		} x != 0 x 0 {
			if ( x % 10 == 3 ){
				System.out.print(" " + i);
				break;
			}
			x /= 10;
		} if ( x % 10 == 3 ){
				System.out.print(" " + i);
				break;
			} x % 10 == 3 x % 10 x 10 3 {
				System.out.print(" " + i);
				break;
			} System.out.print(" " + i) System.out.print System.out System System.out " " + i " " i break; x /= 10 x 10 int i i public class Main {
	static int n;

	public static void main(String[] args) throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        n = Integer.parseInt(br.readLine());
        for(int i = 1; i <= n; i++){
        	if(CHECK_NUM(i)) continue;
        	INCLUDE_3(i);
        }
        System.out.println();
	}

	public static boolean CHECK_NUM(int x){
		if ( x % 3 == 0 ){
			System.out.print(" " + x);
			return true;
		}else{
			return false;
		}
	}

	public static void INCLUDE_3(int i){
		int x = i;
		while(x != 0){
			if ( x % 10 == 3 ){
				System.out.print(" " + i);
				break;
			}
			x /= 10;
		}
	}
} public class Main {
	static int n;

	public static void main(String[] args) throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        n = Integer.parseInt(br.readLine());
        for(int i = 1; i <= n; i++){
        	if(CHECK_NUM(i)) continue;
        	INCLUDE_3(i);
        }
        System.out.println();
	}

	public static boolean CHECK_NUM(int x){
		if ( x % 3 == 0 ){
			System.out.print(" " + x);
			return true;
		}else{
			return false;
		}
	}

	public static void INCLUDE_3(int i){
		int x = i;
		while(x != 0){
			if ( x % 10 == 3 ){
				System.out.print(" " + i);
				break;
			}
			x /= 10;
		}
	}
} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	static int n;

	public static void main(String[] args) throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        n = Integer.parseInt(br.readLine());
        for(int i = 1; i <= n; i++){
        	if(CHECK_NUM(i)) continue;
        	INCLUDE_3(i);
        }
        System.out.println();
	}

	public static boolean CHECK_NUM(int x){
		if ( x % 3 == 0 ){
			System.out.print(" " + x);
			return true;
		}else{
			return false;
		}
	}

	public static void INCLUDE_3(int i){
		int x = i;
		while(x != 0){
			if ( x % 10 == 3 ){
				System.out.print(" " + i);
				break;
			}
			x /= 10;
		}
	}
}