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

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        StringBuilder sb = new StringBuilder();
        for (int i=2; i<n+1; i++){
            String s = String.valueOf(i);
            if (i%3==0){
                sb.append(" "+i);
            }else{
                for (int k=0; k<s.length(); k++){
                    if (s.indexOf('3')!=-1){
                        sb.append(" "+i);
                        break;
                    }
                }
            }
        }
        System.out.println(sb.toString());
    }
} import java.io.IOException; IOException java.io import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        StringBuilder sb = new StringBuilder();
        for (int i=2; i<n+1; i++){
            String s = String.valueOf(i);
            if (i%3==0){
                sb.append(" "+i);
            }else{
                for (int k=0; k<s.length(); k++){
                    if (s.indexOf('3')!=-1){
                        sb.append(" "+i);
                        break;
                    }
                }
            }
        }
        System.out.println(sb.toString());
    }
} Main public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        StringBuilder sb = new StringBuilder();
        for (int i=2; i<n+1; i++){
            String s = String.valueOf(i);
            if (i%3==0){
                sb.append(" "+i);
            }else{
                for (int k=0; k<s.length(); k++){
                    if (s.indexOf('3')!=-1){
                        sb.append(" "+i);
                        break;
                    }
                }
            }
        }
        System.out.println(sb.toString());
    } main {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        StringBuilder sb = new StringBuilder();
        for (int i=2; i<n+1; i++){
            String s = String.valueOf(i);
            if (i%3==0){
                sb.append(" "+i);
            }else{
                for (int k=0; k<s.length(); k++){
                    if (s.indexOf('3')!=-1){
                        sb.append(" "+i);
                        break;
                    }
                }
            }
        }
        System.out.println(sb.toString());
    } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) int n = Integer.parseInt(br.readLine()); n Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br StringBuilder sb = new StringBuilder(); sb new StringBuilder() for (int i=2; i<n+1; i++){
            String s = String.valueOf(i);
            if (i%3==0){
                sb.append(" "+i);
            }else{
                for (int k=0; k<s.length(); k++){
                    if (s.indexOf('3')!=-1){
                        sb.append(" "+i);
                        break;
                    }
                }
            }
        } int i=2; int i=2; i 2 i<n+1 i n+1 n 1 i++ i++ i {
            String s = String.valueOf(i);
            if (i%3==0){
                sb.append(" "+i);
            }else{
                for (int k=0; k<s.length(); k++){
                    if (s.indexOf('3')!=-1){
                        sb.append(" "+i);
                        break;
                    }
                }
            }
        } {
            String s = String.valueOf(i);
            if (i%3==0){
                sb.append(" "+i);
            }else{
                for (int k=0; k<s.length(); k++){
                    if (s.indexOf('3')!=-1){
                        sb.append(" "+i);
                        break;
                    }
                }
            }
        } String s = String.valueOf(i); s String.valueOf(i) String.valueOf String i if (i%3==0){
                sb.append(" "+i);
            }else{
                for (int k=0; k<s.length(); k++){
                    if (s.indexOf('3')!=-1){
                        sb.append(" "+i);
                        break;
                    }
                }
            } i%3==0 i%3 i 3 0 {
                sb.append(" "+i);
            } sb.append(" "+i) sb.append sb " "+i " " i {
                for (int k=0; k<s.length(); k++){
                    if (s.indexOf('3')!=-1){
                        sb.append(" "+i);
                        break;
                    }
                }
            } for (int k=0; k<s.length(); k++){
                    if (s.indexOf('3')!=-1){
                        sb.append(" "+i);
                        break;
                    }
                } int k=0; int k=0; k 0 k<s.length() k s.length() s.length s k++ k++ k {
                    if (s.indexOf('3')!=-1){
                        sb.append(" "+i);
                        break;
                    }
                } {
                    if (s.indexOf('3')!=-1){
                        sb.append(" "+i);
                        break;
                    }
                } if (s.indexOf('3')!=-1){
                        sb.append(" "+i);
                        break;
                    } s.indexOf('3')!=-1 s.indexOf('3') s.indexOf s '3' -1 1 {
                        sb.append(" "+i);
                        break;
                    } sb.append(" "+i) sb.append sb " "+i " " i break; System.out.println(sb.toString()) System.out.println System.out System System.out sb.toString() sb.toString sb String[] args args public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        StringBuilder sb = new StringBuilder();
        for (int i=2; i<n+1; i++){
            String s = String.valueOf(i);
            if (i%3==0){
                sb.append(" "+i);
            }else{
                for (int k=0; k<s.length(); k++){
                    if (s.indexOf('3')!=-1){
                        sb.append(" "+i);
                        break;
                    }
                }
            }
        }
        System.out.println(sb.toString());
    }
} public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        StringBuilder sb = new StringBuilder();
        for (int i=2; i<n+1; i++){
            String s = String.valueOf(i);
            if (i%3==0){
                sb.append(" "+i);
            }else{
                for (int k=0; k<s.length(); k++){
                    if (s.indexOf('3')!=-1){
                        sb.append(" "+i);
                        break;
                    }
                }
            }
        }
        System.out.println(sb.toString());
    }
} Main
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        StringBuilder sb = new StringBuilder();
        for (int i=2; i<n+1; i++){
            String s = String.valueOf(i);
            if (i%3==0){
                sb.append(" "+i);
            }else{
                for (int k=0; k<s.length(); k++){
                    if (s.indexOf('3')!=-1){
                        sb.append(" "+i);
                        break;
                    }
                }
            }
        }
        System.out.println(sb.toString());
    }
}