import java.io.*;
 
class Main {
    static void call(int n){
        StringBuilder output = new StringBuilder();
        for(int i=3; i<=n; i++) {
            int x=i;
            if(x%3==0) {
                output.append(" "+i);
                continue;
            }
            do{
                if(x%10==3) {
                    output.append(" "+i);
                    break;
                }
                x/=10;
            }while(x!=0);
        }
        System.out.println(output);
    }
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        call(n);
    }
} import java.io.*; io.* java class Main {
    static void call(int n){
        StringBuilder output = new StringBuilder();
        for(int i=3; i<=n; i++) {
            int x=i;
            if(x%3==0) {
                output.append(" "+i);
                continue;
            }
            do{
                if(x%10==3) {
                    output.append(" "+i);
                    break;
                }
                x/=10;
            }while(x!=0);
        }
        System.out.println(output);
    }
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        call(n);
    }
} Main static void call(int n){
        StringBuilder output = new StringBuilder();
        for(int i=3; i<=n; i++) {
            int x=i;
            if(x%3==0) {
                output.append(" "+i);
                continue;
            }
            do{
                if(x%10==3) {
                    output.append(" "+i);
                    break;
                }
                x/=10;
            }while(x!=0);
        }
        System.out.println(output);
    } call {
        StringBuilder output = new StringBuilder();
        for(int i=3; i<=n; i++) {
            int x=i;
            if(x%3==0) {
                output.append(" "+i);
                continue;
            }
            do{
                if(x%10==3) {
                    output.append(" "+i);
                    break;
                }
                x/=10;
            }while(x!=0);
        }
        System.out.println(output);
    } StringBuilder output = new StringBuilder(); output new StringBuilder() for(int i=3; i<=n; i++) {
            int x=i;
            if(x%3==0) {
                output.append(" "+i);
                continue;
            }
            do{
                if(x%10==3) {
                    output.append(" "+i);
                    break;
                }
                x/=10;
            }while(x!=0);
        } int i=3; int i=3; i 3 i<=n i n i++ i++ i {
            int x=i;
            if(x%3==0) {
                output.append(" "+i);
                continue;
            }
            do{
                if(x%10==3) {
                    output.append(" "+i);
                    break;
                }
                x/=10;
            }while(x!=0);
        } {
            int x=i;
            if(x%3==0) {
                output.append(" "+i);
                continue;
            }
            do{
                if(x%10==3) {
                    output.append(" "+i);
                    break;
                }
                x/=10;
            }while(x!=0);
        } int x=i; x i if(x%3==0) {
                output.append(" "+i);
                continue;
            } x%3==0 x%3 x 3 0 {
                output.append(" "+i);
                continue;
            } output.append(" "+i) output.append output " "+i " " i continue; do{
                if(x%10==3) {
                    output.append(" "+i);
                    break;
                }
                x/=10;
            }while(x!=0); x!=0 x 0 {
                if(x%10==3) {
                    output.append(" "+i);
                    break;
                }
                x/=10;
            } if(x%10==3) {
                    output.append(" "+i);
                    break;
                } x%10==3 x%10 x 10 3 {
                    output.append(" "+i);
                    break;
                } output.append(" "+i) output.append output " "+i " " i break; x/=10 x 10 System.out.println(output) System.out.println System.out System System.out output int n n public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        call(n);
    } main {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        call(n);
    } 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 call(n) call n String[] args args
import java.io.*;
 
class Main {
    static void call(int n){
        StringBuilder output = new StringBuilder();
        for(int i=3; i<=n; i++) {
            int x=i;
            if(x%3==0) {
                output.append(" "+i);
                continue;
            }
            do{
                if(x%10==3) {
                    output.append(" "+i);
                    break;
                }
                x/=10;
            }while(x!=0);
        }
        System.out.println(output);
    }
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        call(n);
    }
}