import java.util.Scanner;
class Main{
    int n,x,y,z;
    public void solve(){
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        for(x = 3; x <= n; x++){
            y = x;
            z = 0;

                if(y % 3 == 0){
                    System.out.printf(" %d",x);
                    z++;
                }else{
                    while(z == 0){
                        if(y % 10 == 3){
                            System.out.printf(" %d",x);
                            z++;
                        }
                        y /= 10;
                        if(y < 3){
                            z++;
                        }
                    }   
                }
        }
        System.out.println();
    }
    public static void main(String[] args){
        new Main().solve();
    }
} import java.util.Scanner; Scanner java.util class Main{
    int n,x,y,z;
    public void solve(){
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        for(x = 3; x <= n; x++){
            y = x;
            z = 0;

                if(y % 3 == 0){
                    System.out.printf(" %d",x);
                    z++;
                }else{
                    while(z == 0){
                        if(y % 10 == 3){
                            System.out.printf(" %d",x);
                            z++;
                        }
                        y /= 10;
                        if(y < 3){
                            z++;
                        }
                    }   
                }
        }
        System.out.println();
    }
    public static void main(String[] args){
        new Main().solve();
    }
} Main int n n x x y y z; z public void solve(){
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        for(x = 3; x <= n; x++){
            y = x;
            z = 0;

                if(y % 3 == 0){
                    System.out.printf(" %d",x);
                    z++;
                }else{
                    while(z == 0){
                        if(y % 10 == 3){
                            System.out.printf(" %d",x);
                            z++;
                        }
                        y /= 10;
                        if(y < 3){
                            z++;
                        }
                    }   
                }
        }
        System.out.println();
    } solve {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        for(x = 3; x <= n; x++){
            y = x;
            z = 0;

                if(y % 3 == 0){
                    System.out.printf(" %d",x);
                    z++;
                }else{
                    while(z == 0){
                        if(y % 10 == 3){
                            System.out.printf(" %d",x);
                            z++;
                        }
                        y /= 10;
                        if(y < 3){
                            z++;
                        }
                    }   
                }
        }
        System.out.println();
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) n = sc.nextInt() n sc.nextInt() sc.nextInt sc for(x = 3; x <= n; x++){
            y = x;
            z = 0;

                if(y % 3 == 0){
                    System.out.printf(" %d",x);
                    z++;
                }else{
                    while(z == 0){
                        if(y % 10 == 3){
                            System.out.printf(" %d",x);
                            z++;
                        }
                        y /= 10;
                        if(y < 3){
                            z++;
                        }
                    }   
                }
        } x = 3; x = 3 x 3 x <= n x n x++ x++ x {
            y = x;
            z = 0;

                if(y % 3 == 0){
                    System.out.printf(" %d",x);
                    z++;
                }else{
                    while(z == 0){
                        if(y % 10 == 3){
                            System.out.printf(" %d",x);
                            z++;
                        }
                        y /= 10;
                        if(y < 3){
                            z++;
                        }
                    }   
                }
        } {
            y = x;
            z = 0;

                if(y % 3 == 0){
                    System.out.printf(" %d",x);
                    z++;
                }else{
                    while(z == 0){
                        if(y % 10 == 3){
                            System.out.printf(" %d",x);
                            z++;
                        }
                        y /= 10;
                        if(y < 3){
                            z++;
                        }
                    }   
                }
        } y = x y x z = 0 z 0 if(y % 3 == 0){
                    System.out.printf(" %d",x);
                    z++;
                }else{
                    while(z == 0){
                        if(y % 10 == 3){
                            System.out.printf(" %d",x);
                            z++;
                        }
                        y /= 10;
                        if(y < 3){
                            z++;
                        }
                    }   
                } y % 3 == 0 y % 3 y 3 0 {
                    System.out.printf(" %d",x);
                    z++;
                } System.out.printf(" %d",x) System.out.printf System.out System System.out " %d" x z++ z {
                    while(z == 0){
                        if(y % 10 == 3){
                            System.out.printf(" %d",x);
                            z++;
                        }
                        y /= 10;
                        if(y < 3){
                            z++;
                        }
                    }   
                } while(z == 0){
                        if(y % 10 == 3){
                            System.out.printf(" %d",x);
                            z++;
                        }
                        y /= 10;
                        if(y < 3){
                            z++;
                        }
                    } z == 0 z 0 {
                        if(y % 10 == 3){
                            System.out.printf(" %d",x);
                            z++;
                        }
                        y /= 10;
                        if(y < 3){
                            z++;
                        }
                    } if(y % 10 == 3){
                            System.out.printf(" %d",x);
                            z++;
                        } y % 10 == 3 y % 10 y 10 3 {
                            System.out.printf(" %d",x);
                            z++;
                        } System.out.printf(" %d",x) System.out.printf System.out System System.out " %d" x z++ z y /= 10 y 10 if(y < 3){
                            z++;
                        } y < 3 y 3 {
                            z++;
                        } z++ z System.out.println() System.out.println System.out System System.out public static void main(String[] args){
        new Main().solve();
    } main {
        new Main().solve();
    } new Main().solve() new Main().solve new Main() String[] args args
import java.util.Scanner;
class Main{
    int n,x,y,z;
    public void solve(){
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        for(x = 3; x <= n; x++){
            y = x;
            z = 0;

                if(y % 3 == 0){
                    System.out.printf(" %d",x);
                    z++;
                }else{
                    while(z == 0){
                        if(y % 10 == 3){
                            System.out.printf(" %d",x);
                            z++;
                        }
                        y /= 10;
                        if(y < 3){
                            z++;
                        }
                    }   
                }
        }
        System.out.println();
    }
    public static void main(String[] args){
        new Main().solve();
    }
}