import java.io.*;
import java.util.*;

class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n=Integer.parseInt(br.readLine());
        call(n);
    }
    
    static void call(int n){
        for(int i=1;i<=n;i++){
            if(check(i)) System.out.print(" "+i);
        }System.out.println();
    }
    
    static boolean check(int n){
        if(n>=10){
            char[] c=String.valueOf(n).toCharArray();
            for(char checker:c){
                if(checker=='3'){
                    return true;
                }
            }
        }if(n%3==0) return true;
        return false;
    }
} import java.io.*; io.* java import java.util.*; util.* java class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n=Integer.parseInt(br.readLine());
        call(n);
    }
    
    static void call(int n){
        for(int i=1;i<=n;i++){
            if(check(i)) System.out.print(" "+i);
        }System.out.println();
    }
    
    static boolean check(int n){
        if(n>=10){
            char[] c=String.valueOf(n).toCharArray();
            for(char checker:c){
                if(checker=='3'){
                    return true;
                }
            }
        }if(n%3==0) return true;
        return false;
    }
} Main 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 static void call(int n){
        for(int i=1;i<=n;i++){
            if(check(i)) System.out.print(" "+i);
        }System.out.println();
    } call {
        for(int i=1;i<=n;i++){
            if(check(i)) System.out.print(" "+i);
        }System.out.println();
    } for(int i=1;i<=n;i++){
            if(check(i)) System.out.print(" "+i);
        } int i=1; int i=1; i 1 i<=n i n i++ i++ i {
            if(check(i)) System.out.print(" "+i);
        } {
            if(check(i)) System.out.print(" "+i);
        } if(check(i)) System.out.print(" "+i); check(i) check i System.out.print(" "+i) System.out.print System.out System System.out " "+i " " i System.out.println() System.out.println System.out System System.out int n n static boolean check(int n){
        if(n>=10){
            char[] c=String.valueOf(n).toCharArray();
            for(char checker:c){
                if(checker=='3'){
                    return true;
                }
            }
        }if(n%3==0) return true;
        return false;
    } check {
        if(n>=10){
            char[] c=String.valueOf(n).toCharArray();
            for(char checker:c){
                if(checker=='3'){
                    return true;
                }
            }
        }if(n%3==0) return true;
        return false;
    } if(n>=10){
            char[] c=String.valueOf(n).toCharArray();
            for(char checker:c){
                if(checker=='3'){
                    return true;
                }
            }
        } n>=10 n 10 {
            char[] c=String.valueOf(n).toCharArray();
            for(char checker:c){
                if(checker=='3'){
                    return true;
                }
            }
        } char[] c=String.valueOf(n).toCharArray(); c String.valueOf(n).toCharArray() String.valueOf(n).toCharArray String.valueOf(n) String.valueOf String n for(char checker:c){
                if(checker=='3'){
                    return true;
                }
            } char checker c {
                if(checker=='3'){
                    return true;
                }
            } {
                if(checker=='3'){
                    return true;
                }
            } if(checker=='3'){
                    return true;
                } checker=='3' checker '3' {
                    return true;
                } return true; true if(n%3==0) return true; n%3==0 n%3 n 3 0 return true; true return false; false int n n
import java.io.*;
import java.util.*;

class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n=Integer.parseInt(br.readLine());
        call(n);
    }
    
    static void call(int n){
        for(int i=1;i<=n;i++){
            if(check(i)) System.out.print(" "+i);
        }System.out.println();
    }
    
    static boolean check(int n){
        if(n>=10){
            char[] c=String.valueOf(n).toCharArray();
            for(char checker:c){
                if(checker=='3'){
                    return true;
                }
            }
        }if(n%3==0) return true;
        return false;
    }
}