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

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder builder = new StringBuilder();
        String line = reader.readLine();
        int x = Integer.parseInt(line);

        call(1, x, builder);
        System.out.println(builder);
    }

    public static void call(int i, int n, StringBuilder builder) {
        // 3??§?????????????????? ??????
        while (i <= n) {
            int x = i;
            if (x % 3 == 0) {
                builder.append(" " + i);
            }
            else {
                // INCLUDE3
                int y = x;
                while (y > 1) {
                    if (y % 10 == 3) {
                        builder.append(" " + i);
                        break;
                    }
                    y = y / 10;
                }
            }
            i++;
        }
    }
} 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 reader = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder builder = new StringBuilder();
        String line = reader.readLine();
        int x = Integer.parseInt(line);

        call(1, x, builder);
        System.out.println(builder);
    }

    public static void call(int i, int n, StringBuilder builder) {
        // 3??§?????????????????? ??????
        while (i <= n) {
            int x = i;
            if (x % 3 == 0) {
                builder.append(" " + i);
            }
            else {
                // INCLUDE3
                int y = x;
                while (y > 1) {
                    if (y % 10 == 3) {
                        builder.append(" " + i);
                        break;
                    }
                    y = y / 10;
                }
            }
            i++;
        }
    }
} Main public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder builder = new StringBuilder();
        String line = reader.readLine();
        int x = Integer.parseInt(line);

        call(1, x, builder);
        System.out.println(builder);
    } main {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder builder = new StringBuilder();
        String line = reader.readLine();
        int x = Integer.parseInt(line);

        call(1, x, builder);
        System.out.println(builder);
    } BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); reader new BufferedReader(new InputStreamReader(System.in)) StringBuilder builder = new StringBuilder(); builder new StringBuilder() String line = reader.readLine(); line reader.readLine() reader.readLine reader int x = Integer.parseInt(line); x Integer.parseInt(line) Integer.parseInt Integer line call(1, x, builder) call 1 x builder System.out.println(builder) System.out.println System.out System System.out builder String[] args args public static void call(int i, int n, StringBuilder builder) {
        // 3??§?????????????????? ??????
        while (i <= n) {
            int x = i;
            if (x % 3 == 0) {
                builder.append(" " + i);
            }
            else {
                // INCLUDE3
                int y = x;
                while (y > 1) {
                    if (y % 10 == 3) {
                        builder.append(" " + i);
                        break;
                    }
                    y = y / 10;
                }
            }
            i++;
        }
    } call {
        // 3??§?????????????????? ??????
        while (i <= n) {
            int x = i;
            if (x % 3 == 0) {
                builder.append(" " + i);
            }
            else {
                // INCLUDE3
                int y = x;
                while (y > 1) {
                    if (y % 10 == 3) {
                        builder.append(" " + i);
                        break;
                    }
                    y = y / 10;
                }
            }
            i++;
        }
    } while (i <= n) {
            int x = i;
            if (x % 3 == 0) {
                builder.append(" " + i);
            }
            else {
                // INCLUDE3
                int y = x;
                while (y > 1) {
                    if (y % 10 == 3) {
                        builder.append(" " + i);
                        break;
                    }
                    y = y / 10;
                }
            }
            i++;
        } i <= n i n {
            int x = i;
            if (x % 3 == 0) {
                builder.append(" " + i);
            }
            else {
                // INCLUDE3
                int y = x;
                while (y > 1) {
                    if (y % 10 == 3) {
                        builder.append(" " + i);
                        break;
                    }
                    y = y / 10;
                }
            }
            i++;
        } int x = i; x i if (x % 3 == 0) {
                builder.append(" " + i);
            }
            else {
                // INCLUDE3
                int y = x;
                while (y > 1) {
                    if (y % 10 == 3) {
                        builder.append(" " + i);
                        break;
                    }
                    y = y / 10;
                }
            } x % 3 == 0 x % 3 x 3 0 {
                builder.append(" " + i);
            } builder.append(" " + i) builder.append builder " " + i " " i {
                // INCLUDE3
                int y = x;
                while (y > 1) {
                    if (y % 10 == 3) {
                        builder.append(" " + i);
                        break;
                    }
                    y = y / 10;
                }
            } int y = x; y x while (y > 1) {
                    if (y % 10 == 3) {
                        builder.append(" " + i);
                        break;
                    }
                    y = y / 10;
                } y > 1 y 1 {
                    if (y % 10 == 3) {
                        builder.append(" " + i);
                        break;
                    }
                    y = y / 10;
                } if (y % 10 == 3) {
                        builder.append(" " + i);
                        break;
                    } y % 10 == 3 y % 10 y 10 3 {
                        builder.append(" " + i);
                        break;
                    } builder.append(" " + i) builder.append builder " " + i " " i break; y = y / 10 y y / 10 y 10 i++ i int i i int n n StringBuilder builder builder public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder builder = new StringBuilder();
        String line = reader.readLine();
        int x = Integer.parseInt(line);

        call(1, x, builder);
        System.out.println(builder);
    }

    public static void call(int i, int n, StringBuilder builder) {
        // 3??§?????????????????? ??????
        while (i <= n) {
            int x = i;
            if (x % 3 == 0) {
                builder.append(" " + i);
            }
            else {
                // INCLUDE3
                int y = x;
                while (y > 1) {
                    if (y % 10 == 3) {
                        builder.append(" " + i);
                        break;
                    }
                    y = y / 10;
                }
            }
            i++;
        }
    }
} public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder builder = new StringBuilder();
        String line = reader.readLine();
        int x = Integer.parseInt(line);

        call(1, x, builder);
        System.out.println(builder);
    }

    public static void call(int i, int n, StringBuilder builder) {
        // 3??§?????????????????? ??????
        while (i <= n) {
            int x = i;
            if (x % 3 == 0) {
                builder.append(" " + i);
            }
            else {
                // INCLUDE3
                int y = x;
                while (y > 1) {
                    if (y % 10 == 3) {
                        builder.append(" " + i);
                        break;
                    }
                    y = y / 10;
                }
            }
            i++;
        }
    }
} 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 reader = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder builder = new StringBuilder();
        String line = reader.readLine();
        int x = Integer.parseInt(line);

        call(1, x, builder);
        System.out.println(builder);
    }

    public static void call(int i, int n, StringBuilder builder) {
        // 3??§?????????????????? ??????
        while (i <= n) {
            int x = i;
            if (x % 3 == 0) {
                builder.append(" " + i);
            }
            else {
                // INCLUDE3
                int y = x;
                while (y > 1) {
                    if (y % 10 == 3) {
                        builder.append(" " + i);
                        break;
                    }
                    y = y / 10;
                }
            }
            i++;
        }
    }
}