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

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

class Main{
    private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    private static final PrintWriter out = new PrintWriter(System.out);
    public static void main(String[] Args) throws IOException{
        final int n = Integer.parseInt(br.readLine());
        for(int i = 1; i<=n; i++){
            int x = i;
            if(x%3==0){
                out.print(" "+i);
                continue;
            }
            do{
                if(x%10==3){
                    out.print(" "+i);
                    break;
                }
                x /= 10;
            }while(x!=0);
        }
        out.println();
        out.flush();
    }
}