import java.util.Scanner;

public class Main {
    /**
     * x???d?????????????????????
     * d????????¨????????°???
     * @return
     */
    public static boolean contain(int x, int d) {
        String s = String.format("%d", x);
        return s.contains(String.format("%d", d));
    }
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        for(int i=3;i<=n;i++) {
            if((i % 3) == 0 || contain(i, 3)) {
                System.out.print(" " + i);
            }
        }
        System.out.println("");
    }
} import java.util.Scanner; Scanner java.util public class Main {
    /**
     * x???d?????????????????????
     * d????????¨????????°???
     * @return
     */
    public static boolean contain(int x, int d) {
        String s = String.format("%d", x);
        return s.contains(String.format("%d", d));
    }
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        for(int i=3;i<=n;i++) {
            if((i % 3) == 0 || contain(i, 3)) {
                System.out.print(" " + i);
            }
        }
        System.out.println("");
    }
} Main /**
     * x???d?????????????????????
     * d????????¨????????°???
     * @return
     */
    public static boolean contain(int x, int d) {
        String s = String.format("%d", x);
        return s.contains(String.format("%d", d));
    } contain {
        String s = String.format("%d", x);
        return s.contains(String.format("%d", d));
    } String s = String.format("%d", x); s String.format("%d", x) String.format String "%d" x return s.contains(String.format("%d", d)); s.contains(String.format("%d", d)) s.contains s String.format("%d", d) String.format String "%d" d int x x int d d public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        for(int i=3;i<=n;i++) {
            if((i % 3) == 0 || contain(i, 3)) {
                System.out.print(" " + i);
            }
        }
        System.out.println("");
    } main {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        for(int i=3;i<=n;i++) {
            if((i % 3) == 0 || contain(i, 3)) {
                System.out.print(" " + i);
            }
        }
        System.out.println("");
    } Scanner in = new Scanner(System.in); in new Scanner(System.in) int n = in.nextInt(); n in.nextInt() in.nextInt in for(int i=3;i<=n;i++) {
            if((i % 3) == 0 || contain(i, 3)) {
                System.out.print(" " + i);
            }
        } int i=3; int i=3; i 3 i<=n i n i++ i++ i {
            if((i % 3) == 0 || contain(i, 3)) {
                System.out.print(" " + i);
            }
        } {
            if((i % 3) == 0 || contain(i, 3)) {
                System.out.print(" " + i);
            }
        } if((i % 3) == 0 || contain(i, 3)) {
                System.out.print(" " + i);
            } (i % 3) == 0 || contain(i, 3) (i % 3) == 0 (i % 3) i 3 0 contain(i, 3) contain i 3 {
                System.out.print(" " + 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 "" String[] args args public class Main {
    /**
     * x???d?????????????????????
     * d????????¨????????°???
     * @return
     */
    public static boolean contain(int x, int d) {
        String s = String.format("%d", x);
        return s.contains(String.format("%d", d));
    }
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        for(int i=3;i<=n;i++) {
            if((i % 3) == 0 || contain(i, 3)) {
                System.out.print(" " + i);
            }
        }
        System.out.println("");
    }
} public class Main {
    /**
     * x???d?????????????????????
     * d????????¨????????°???
     * @return
     */
    public static boolean contain(int x, int d) {
        String s = String.format("%d", x);
        return s.contains(String.format("%d", d));
    }
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        for(int i=3;i<=n;i++) {
            if((i % 3) == 0 || contain(i, 3)) {
                System.out.print(" " + i);
            }
        }
        System.out.println("");
    }
} Main
import java.util.Scanner;

public class Main {
    /**
     * x???d?????????????????????
     * d????????¨????????°???
     * @return
     */
    public static boolean contain(int x, int d) {
        String s = String.format("%d", x);
        return s.contains(String.format("%d", d));
    }
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        for(int i=3;i<=n;i++) {
            if((i % 3) == 0 || contain(i, 3)) {
                System.out.print(" " + i);
            }
        }
        System.out.println("");
    }
}