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

public class Main {
    public static void main(String[] args)throws Exception {
    	InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(isr);

        int n = Integer.parseInt(br.readLine());
        for(int x = 1 ; x <= n; x++){
        	if(x % 3 == 0){
        		System.out.print(" " + x);
        	}else {
        		Integer m = new Integer(x);
        		String k = m.toString();
        		for(int y = 0; y < k.length(); y++){
        			String str = String.valueOf(k.charAt(y));
        			if(str.equals ("3")){
        				System.out.print(" " + x);
        				break;
        			}
        		}
        	}
        }
        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 {
    	InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(isr);

        int n = Integer.parseInt(br.readLine());
        for(int x = 1 ; x <= n; x++){
        	if(x % 3 == 0){
        		System.out.print(" " + x);
        	}else {
        		Integer m = new Integer(x);
        		String k = m.toString();
        		for(int y = 0; y < k.length(); y++){
        			String str = String.valueOf(k.charAt(y));
        			if(str.equals ("3")){
        				System.out.print(" " + x);
        				break;
        			}
        		}
        	}
        }
        System.out.println();
    }
} Main public static void main(String[] args)throws Exception {
    	InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(isr);

        int n = Integer.parseInt(br.readLine());
        for(int x = 1 ; x <= n; x++){
        	if(x % 3 == 0){
        		System.out.print(" " + x);
        	}else {
        		Integer m = new Integer(x);
        		String k = m.toString();
        		for(int y = 0; y < k.length(); y++){
        			String str = String.valueOf(k.charAt(y));
        			if(str.equals ("3")){
        				System.out.print(" " + x);
        				break;
        			}
        		}
        	}
        }
        System.out.println();
    } main {
    	InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(isr);

        int n = Integer.parseInt(br.readLine());
        for(int x = 1 ; x <= n; x++){
        	if(x % 3 == 0){
        		System.out.print(" " + x);
        	}else {
        		Integer m = new Integer(x);
        		String k = m.toString();
        		for(int y = 0; y < k.length(); y++){
        			String str = String.valueOf(k.charAt(y));
        			if(str.equals ("3")){
        				System.out.print(" " + x);
        				break;
        			}
        		}
        	}
        }
        System.out.println();
    } InputStreamReader isr = new InputStreamReader(System.in); isr new InputStreamReader(System.in) BufferedReader br = new BufferedReader(isr); br new BufferedReader(isr) int n = Integer.parseInt(br.readLine()); n Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br for(int x = 1 ; x <= n; x++){
        	if(x % 3 == 0){
        		System.out.print(" " + x);
        	}else {
        		Integer m = new Integer(x);
        		String k = m.toString();
        		for(int y = 0; y < k.length(); y++){
        			String str = String.valueOf(k.charAt(y));
        			if(str.equals ("3")){
        				System.out.print(" " + x);
        				break;
        			}
        		}
        	}
        } int x = 1 ; int x = 1 ; x 1 x <= n x n x++ x++ x {
        	if(x % 3 == 0){
        		System.out.print(" " + x);
        	}else {
        		Integer m = new Integer(x);
        		String k = m.toString();
        		for(int y = 0; y < k.length(); y++){
        			String str = String.valueOf(k.charAt(y));
        			if(str.equals ("3")){
        				System.out.print(" " + x);
        				break;
        			}
        		}
        	}
        } {
        	if(x % 3 == 0){
        		System.out.print(" " + x);
        	}else {
        		Integer m = new Integer(x);
        		String k = m.toString();
        		for(int y = 0; y < k.length(); y++){
        			String str = String.valueOf(k.charAt(y));
        			if(str.equals ("3")){
        				System.out.print(" " + x);
        				break;
        			}
        		}
        	}
        } if(x % 3 == 0){
        		System.out.print(" " + x);
        	}else {
        		Integer m = new Integer(x);
        		String k = m.toString();
        		for(int y = 0; y < k.length(); y++){
        			String str = String.valueOf(k.charAt(y));
        			if(str.equals ("3")){
        				System.out.print(" " + x);
        				break;
        			}
        		}
        	} x % 3 == 0 x % 3 x 3 0 {
        		System.out.print(" " + x);
        	} System.out.print(" " + x) System.out.print System.out System System.out " " + x " " x {
        		Integer m = new Integer(x);
        		String k = m.toString();
        		for(int y = 0; y < k.length(); y++){
        			String str = String.valueOf(k.charAt(y));
        			if(str.equals ("3")){
        				System.out.print(" " + x);
        				break;
        			}
        		}
        	} Integer m = new Integer(x); m new Integer(x) String k = m.toString(); k m.toString() m.toString m for(int y = 0; y < k.length(); y++){
        			String str = String.valueOf(k.charAt(y));
        			if(str.equals ("3")){
        				System.out.print(" " + x);
        				break;
        			}
        		} int y = 0; int y = 0; y 0 y < k.length() y k.length() k.length k y++ y++ y {
        			String str = String.valueOf(k.charAt(y));
        			if(str.equals ("3")){
        				System.out.print(" " + x);
        				break;
        			}
        		} {
        			String str = String.valueOf(k.charAt(y));
        			if(str.equals ("3")){
        				System.out.print(" " + x);
        				break;
        			}
        		} String str = String.valueOf(k.charAt(y)); str String.valueOf(k.charAt(y)) String.valueOf String k.charAt(y) k.charAt k y if(str.equals ("3")){
        				System.out.print(" " + x);
        				break;
        			} str.equals ("3") str.equals str "3" {
        				System.out.print(" " + x);
        				break;
        			} System.out.print(" " + x) System.out.print System.out System System.out " " + x " " x break; System.out.println() System.out.println System.out System System.out String[] args args public class Main {
    public static void main(String[] args)throws Exception {
    	InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(isr);

        int n = Integer.parseInt(br.readLine());
        for(int x = 1 ; x <= n; x++){
        	if(x % 3 == 0){
        		System.out.print(" " + x);
        	}else {
        		Integer m = new Integer(x);
        		String k = m.toString();
        		for(int y = 0; y < k.length(); y++){
        			String str = String.valueOf(k.charAt(y));
        			if(str.equals ("3")){
        				System.out.print(" " + x);
        				break;
        			}
        		}
        	}
        }
        System.out.println();
    }
} public class Main {
    public static void main(String[] args)throws Exception {
    	InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(isr);

        int n = Integer.parseInt(br.readLine());
        for(int x = 1 ; x <= n; x++){
        	if(x % 3 == 0){
        		System.out.print(" " + x);
        	}else {
        		Integer m = new Integer(x);
        		String k = m.toString();
        		for(int y = 0; y < k.length(); y++){
        			String str = String.valueOf(k.charAt(y));
        			if(str.equals ("3")){
        				System.out.print(" " + x);
        				break;
        			}
        		}
        	}
        }
        System.out.println();
    }
} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args)throws Exception {
    	InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(isr);

        int n = Integer.parseInt(br.readLine());
        for(int x = 1 ; x <= n; x++){
        	if(x % 3 == 0){
        		System.out.print(" " + x);
        	}else {
        		Integer m = new Integer(x);
        		String k = m.toString();
        		for(int y = 0; y < k.length(); y++){
        			String str = String.valueOf(k.charAt(y));
        			if(str.equals ("3")){
        				System.out.print(" " + x);
        				break;
        			}
        		}
        	}
        }
        System.out.println();
    }
}