import java.util.Scanner;
class Main{
    int n,x;
    public void solve(){
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();

        for(x = 1; x <= n; x++){
            if(x % 3 == 0 || x % 10 == 3){
                System.out.printf(" %d",x);
            }else if(x / 10 == 3 || x / 100 == 3 || x / 1000 == 3 || x / 10000 == 3){
                System.out.printf(" %d",x);
            }else if(x - x / 100 * 100 > 29 && x - x / 100 * 100 < 40){
                System.out.printf(" %d",x);
            }else if(x - x / 1000 * 1000 >= 300 && x - x / 1000 * 1000 < 400){
                System.out.printf(" %d",x);
            }else if(x - x / 10000 * 10000 >= 3000 && x - x / 10000 * 10000 < 4000){
                System.out.printf(" %d",x);
            }
        }

        System.out.println();
    }
    public static void main(String[] args){
        new Main().solve();
    }
} import java.util.Scanner; Scanner java.util class Main{
    int n,x;
    public void solve(){
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();

        for(x = 1; x <= n; x++){
            if(x % 3 == 0 || x % 10 == 3){
                System.out.printf(" %d",x);
            }else if(x / 10 == 3 || x / 100 == 3 || x / 1000 == 3 || x / 10000 == 3){
                System.out.printf(" %d",x);
            }else if(x - x / 100 * 100 > 29 && x - x / 100 * 100 < 40){
                System.out.printf(" %d",x);
            }else if(x - x / 1000 * 1000 >= 300 && x - x / 1000 * 1000 < 400){
                System.out.printf(" %d",x);
            }else if(x - x / 10000 * 10000 >= 3000 && x - x / 10000 * 10000 < 4000){
                System.out.printf(" %d",x);
            }
        }

        System.out.println();
    }
    public static void main(String[] args){
        new Main().solve();
    }
} Main int n n x; x public void solve(){
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();

        for(x = 1; x <= n; x++){
            if(x % 3 == 0 || x % 10 == 3){
                System.out.printf(" %d",x);
            }else if(x / 10 == 3 || x / 100 == 3 || x / 1000 == 3 || x / 10000 == 3){
                System.out.printf(" %d",x);
            }else if(x - x / 100 * 100 > 29 && x - x / 100 * 100 < 40){
                System.out.printf(" %d",x);
            }else if(x - x / 1000 * 1000 >= 300 && x - x / 1000 * 1000 < 400){
                System.out.printf(" %d",x);
            }else if(x - x / 10000 * 10000 >= 3000 && x - x / 10000 * 10000 < 4000){
                System.out.printf(" %d",x);
            }
        }

        System.out.println();
    } solve {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();

        for(x = 1; x <= n; x++){
            if(x % 3 == 0 || x % 10 == 3){
                System.out.printf(" %d",x);
            }else if(x / 10 == 3 || x / 100 == 3 || x / 1000 == 3 || x / 10000 == 3){
                System.out.printf(" %d",x);
            }else if(x - x / 100 * 100 > 29 && x - x / 100 * 100 < 40){
                System.out.printf(" %d",x);
            }else if(x - x / 1000 * 1000 >= 300 && x - x / 1000 * 1000 < 400){
                System.out.printf(" %d",x);
            }else if(x - x / 10000 * 10000 >= 3000 && x - x / 10000 * 10000 < 4000){
                System.out.printf(" %d",x);
            }
        }

        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 = 1; x <= n; x++){
            if(x % 3 == 0 || x % 10 == 3){
                System.out.printf(" %d",x);
            }else if(x / 10 == 3 || x / 100 == 3 || x / 1000 == 3 || x / 10000 == 3){
                System.out.printf(" %d",x);
            }else if(x - x / 100 * 100 > 29 && x - x / 100 * 100 < 40){
                System.out.printf(" %d",x);
            }else if(x - x / 1000 * 1000 >= 300 && x - x / 1000 * 1000 < 400){
                System.out.printf(" %d",x);
            }else if(x - x / 10000 * 10000 >= 3000 && x - x / 10000 * 10000 < 4000){
                System.out.printf(" %d",x);
            }
        } x = 1; x = 1 x 1 x <= n x n x++ x++ x {
            if(x % 3 == 0 || x % 10 == 3){
                System.out.printf(" %d",x);
            }else if(x / 10 == 3 || x / 100 == 3 || x / 1000 == 3 || x / 10000 == 3){
                System.out.printf(" %d",x);
            }else if(x - x / 100 * 100 > 29 && x - x / 100 * 100 < 40){
                System.out.printf(" %d",x);
            }else if(x - x / 1000 * 1000 >= 300 && x - x / 1000 * 1000 < 400){
                System.out.printf(" %d",x);
            }else if(x - x / 10000 * 10000 >= 3000 && x - x / 10000 * 10000 < 4000){
                System.out.printf(" %d",x);
            }
        } {
            if(x % 3 == 0 || x % 10 == 3){
                System.out.printf(" %d",x);
            }else if(x / 10 == 3 || x / 100 == 3 || x / 1000 == 3 || x / 10000 == 3){
                System.out.printf(" %d",x);
            }else if(x - x / 100 * 100 > 29 && x - x / 100 * 100 < 40){
                System.out.printf(" %d",x);
            }else if(x - x / 1000 * 1000 >= 300 && x - x / 1000 * 1000 < 400){
                System.out.printf(" %d",x);
            }else if(x - x / 10000 * 10000 >= 3000 && x - x / 10000 * 10000 < 4000){
                System.out.printf(" %d",x);
            }
        } if(x % 3 == 0 || x % 10 == 3){
                System.out.printf(" %d",x);
            }else if(x / 10 == 3 || x / 100 == 3 || x / 1000 == 3 || x / 10000 == 3){
                System.out.printf(" %d",x);
            }else if(x - x / 100 * 100 > 29 && x - x / 100 * 100 < 40){
                System.out.printf(" %d",x);
            }else if(x - x / 1000 * 1000 >= 300 && x - x / 1000 * 1000 < 400){
                System.out.printf(" %d",x);
            }else if(x - x / 10000 * 10000 >= 3000 && x - x / 10000 * 10000 < 4000){
                System.out.printf(" %d",x);
            } x % 3 == 0 || x % 10 == 3 x % 3 == 0 x % 3 x 3 0 x % 10 == 3 x % 10 x 10 3 {
                System.out.printf(" %d",x);
            } System.out.printf(" %d",x) System.out.printf System.out System System.out " %d" x if(x / 10 == 3 || x / 100 == 3 || x / 1000 == 3 || x / 10000 == 3){
                System.out.printf(" %d",x);
            }else if(x - x / 100 * 100 > 29 && x - x / 100 * 100 < 40){
                System.out.printf(" %d",x);
            }else if(x - x / 1000 * 1000 >= 300 && x - x / 1000 * 1000 < 400){
                System.out.printf(" %d",x);
            }else if(x - x / 10000 * 10000 >= 3000 && x - x / 10000 * 10000 < 4000){
                System.out.printf(" %d",x);
            } x / 10 == 3 || x / 100 == 3 || x / 1000 == 3 || x / 10000 == 3 x / 1000 == 3 x / 10 == 3 || x / 100 == 3 || x / 1000 == 3 || x / 10000 == 3 x / 10 == 3 x / 10 x 10 3 x / 100 == 3 x / 100 x 100 3 x / 1000 == 3 x / 1000 x 1000 3 x / 10000 == 3 x / 10000 x 10000 3 {
                System.out.printf(" %d",x);
            } System.out.printf(" %d",x) System.out.printf System.out System System.out " %d" x if(x - x / 100 * 100 > 29 && x - x / 100 * 100 < 40){
                System.out.printf(" %d",x);
            }else if(x - x / 1000 * 1000 >= 300 && x - x / 1000 * 1000 < 400){
                System.out.printf(" %d",x);
            }else if(x - x / 10000 * 10000 >= 3000 && x - x / 10000 * 10000 < 4000){
                System.out.printf(" %d",x);
            } x - x / 100 * 100 > 29 && x - x / 100 * 100 < 40 x - x / 100 * 100 > 29 x - x / 100 * 100 x x / 100 * 100 x / 100 x 100 100 29 x - x / 100 * 100 < 40 x - x / 100 * 100 x x / 100 * 100 x / 100 x 100 100 40 {
                System.out.printf(" %d",x);
            } System.out.printf(" %d",x) System.out.printf System.out System System.out " %d" x if(x - x / 1000 * 1000 >= 300 && x - x / 1000 * 1000 < 400){
                System.out.printf(" %d",x);
            }else if(x - x / 10000 * 10000 >= 3000 && x - x / 10000 * 10000 < 4000){
                System.out.printf(" %d",x);
            } x - x / 1000 * 1000 >= 300 && x - x / 1000 * 1000 < 400 x - x / 1000 * 1000 >= 300 x - x / 1000 * 1000 x x / 1000 * 1000 x / 1000 x 1000 1000 300 x - x / 1000 * 1000 < 400 x - x / 1000 * 1000 x x / 1000 * 1000 x / 1000 x 1000 1000 400 {
                System.out.printf(" %d",x);
            } System.out.printf(" %d",x) System.out.printf System.out System System.out " %d" x if(x - x / 10000 * 10000 >= 3000 && x - x / 10000 * 10000 < 4000){
                System.out.printf(" %d",x);
            } x - x / 10000 * 10000 >= 3000 && x - x / 10000 * 10000 < 4000 x - x / 10000 * 10000 >= 3000 x - x / 10000 * 10000 x x / 10000 * 10000 x / 10000 x 10000 10000 3000 x - x / 10000 * 10000 < 4000 x - x / 10000 * 10000 x x / 10000 * 10000 x / 10000 x 10000 10000 4000 {
                System.out.printf(" %d",x);
            } System.out.printf(" %d",x) System.out.printf System.out System System.out " %d" x 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;
    public void solve(){
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();

        for(x = 1; x <= n; x++){
            if(x % 3 == 0 || x % 10 == 3){
                System.out.printf(" %d",x);
            }else if(x / 10 == 3 || x / 100 == 3 || x / 1000 == 3 || x / 10000 == 3){
                System.out.printf(" %d",x);
            }else if(x - x / 100 * 100 > 29 && x - x / 100 * 100 < 40){
                System.out.printf(" %d",x);
            }else if(x - x / 1000 * 1000 >= 300 && x - x / 1000 * 1000 < 400){
                System.out.printf(" %d",x);
            }else if(x - x / 10000 * 10000 >= 3000 && x - x / 10000 * 10000 < 4000){
                System.out.printf(" %d",x);
            }
        }

        System.out.println();
    }
    public static void main(String[] args){
        new Main().solve();
    }
}