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

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        for (int i = 3; i <= n; i++) {
            if (i % 3 == 0) {
                System.out.print(" " + i);
            } else {
                String s = String.valueOf(i);
                if (s.contains("3")) {
                    System.out.print(" " + i);
                }
            }
        }
        System.out.println();
    }
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        for (int i = 3; i <= n; i++) {
            if (i % 3 == 0) {
                System.out.print(" " + i);
            } else {
                String s = String.valueOf(i);
                if (s.contains("3")) {
                    System.out.print(" " + i);
                }
            }
        }
        System.out.println();
    }
} Main public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        for (int i = 3; i <= n; i++) {
            if (i % 3 == 0) {
                System.out.print(" " + i);
            } else {
                String s = String.valueOf(i);
                if (s.contains("3")) {
                    System.out.print(" " + i);
                }
            }
        }
        System.out.println();
    } main {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        for (int i = 3; i <= n; i++) {
            if (i % 3 == 0) {
                System.out.print(" " + i);
            } else {
                String s = String.valueOf(i);
                if (s.contains("3")) {
                    System.out.print(" " + i);
                }
            }
        }
        System.out.println();
    } 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 for (int i = 3; i <= n; i++) {
            if (i % 3 == 0) {
                System.out.print(" " + i);
            } else {
                String s = String.valueOf(i);
                if (s.contains("3")) {
                    System.out.print(" " + i);
                }
            }
        } int i = 3; int i = 3; i 3 i <= n i n i++ i++ i {
            if (i % 3 == 0) {
                System.out.print(" " + i);
            } else {
                String s = String.valueOf(i);
                if (s.contains("3")) {
                    System.out.print(" " + i);
                }
            }
        } {
            if (i % 3 == 0) {
                System.out.print(" " + i);
            } else {
                String s = String.valueOf(i);
                if (s.contains("3")) {
                    System.out.print(" " + i);
                }
            }
        } if (i % 3 == 0) {
                System.out.print(" " + i);
            } else {
                String s = String.valueOf(i);
                if (s.contains("3")) {
                    System.out.print(" " + i);
                }
            } i % 3 == 0 i % 3 i 3 0 {
                System.out.print(" " + i);
            } System.out.print(" " + i) System.out.print System.out System System.out " " + i " " i {
                String s = String.valueOf(i);
                if (s.contains("3")) {
                    System.out.print(" " + i);
                }
            } String s = String.valueOf(i); s String.valueOf(i) String.valueOf String i if (s.contains("3")) {
                    System.out.print(" " + i);
                } s.contains("3") s.contains s "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 {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        for (int i = 3; i <= n; i++) {
            if (i % 3 == 0) {
                System.out.print(" " + i);
            } else {
                String s = String.valueOf(i);
                if (s.contains("3")) {
                    System.out.print(" " + i);
                }
            }
        }
        System.out.println();
    }
} public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        for (int i = 3; i <= n; i++) {
            if (i % 3 == 0) {
                System.out.print(" " + i);
            } else {
                String s = String.valueOf(i);
                if (s.contains("3")) {
                    System.out.print(" " + i);
                }
            }
        }
        System.out.println();
    }
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        for (int i = 3; i <= n; i++) {
            if (i % 3 == 0) {
                System.out.print(" " + i);
            } else {
                String s = String.valueOf(i);
                if (s.contains("3")) {
                    System.out.print(" " + i);
                }
            }
        }
        System.out.println();
    }
}