import java.io.*;
import java.util.*;

public class Main {
    void run() {
        int N = readInt();
        for (int i = 1; i <= N; i++) {
            int x = i;
            if (x % 3 == 0) {
                sysout.print(" " + i);
                continue;
            }
            while (x > 0) {
                boolean end = false;
                if (x % 10 == 3) {
                    sysout.print(" " + i);
                    end = true;
                }
                if (end) break;
                x /= 10;
            }
        }
        sysout.println();
    }

    public static void main(String[] args) {
        new Main().run();
    }

    // flush automatically iff you call `println` or `printf` or `format`.
    PrintWriter sysout = new PrintWriter(System.out, true);

    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer buffer = null;

    String readLine() {
        buffer = null;
        try {
            return in.readLine();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    String read() {
        if (buffer == null || !buffer.hasMoreTokens()) {
            buffer = new StringTokenizer(readLine());
        }
        return buffer.nextToken();
    }

    int readInt() {
        return Integer.parseInt(read());
    }

    long readLong() {
        return Long.parseLong(read());
    }

    double readDouble() {
        return Double.parseDouble(read());
    }
} import java.io.*; io.* java import java.util.*; util.* java public class Main {
    void run() {
        int N = readInt();
        for (int i = 1; i <= N; i++) {
            int x = i;
            if (x % 3 == 0) {
                sysout.print(" " + i);
                continue;
            }
            while (x > 0) {
                boolean end = false;
                if (x % 10 == 3) {
                    sysout.print(" " + i);
                    end = true;
                }
                if (end) break;
                x /= 10;
            }
        }
        sysout.println();
    }

    public static void main(String[] args) {
        new Main().run();
    }

    // flush automatically iff you call `println` or `printf` or `format`.
    PrintWriter sysout = new PrintWriter(System.out, true);

    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer buffer = null;

    String readLine() {
        buffer = null;
        try {
            return in.readLine();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    String read() {
        if (buffer == null || !buffer.hasMoreTokens()) {
            buffer = new StringTokenizer(readLine());
        }
        return buffer.nextToken();
    }

    int readInt() {
        return Integer.parseInt(read());
    }

    long readLong() {
        return Long.parseLong(read());
    }

    double readDouble() {
        return Double.parseDouble(read());
    }
} Main // flush automatically iff you call `println` or `printf` or `format`.
    PrintWriter sysout = new PrintWriter(System.out, true); sysout new PrintWriter(System.out, true) BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); in new BufferedReader(new InputStreamReader(System.in)) StringTokenizer buffer = null; buffer null void run() {
        int N = readInt();
        for (int i = 1; i <= N; i++) {
            int x = i;
            if (x % 3 == 0) {
                sysout.print(" " + i);
                continue;
            }
            while (x > 0) {
                boolean end = false;
                if (x % 10 == 3) {
                    sysout.print(" " + i);
                    end = true;
                }
                if (end) break;
                x /= 10;
            }
        }
        sysout.println();
    } run {
        int N = readInt();
        for (int i = 1; i <= N; i++) {
            int x = i;
            if (x % 3 == 0) {
                sysout.print(" " + i);
                continue;
            }
            while (x > 0) {
                boolean end = false;
                if (x % 10 == 3) {
                    sysout.print(" " + i);
                    end = true;
                }
                if (end) break;
                x /= 10;
            }
        }
        sysout.println();
    } int N = readInt(); N readInt() readInt for (int i = 1; i <= N; i++) {
            int x = i;
            if (x % 3 == 0) {
                sysout.print(" " + i);
                continue;
            }
            while (x > 0) {
                boolean end = false;
                if (x % 10 == 3) {
                    sysout.print(" " + i);
                    end = true;
                }
                if (end) break;
                x /= 10;
            }
        } int i = 1; int i = 1; i 1 i <= N i N i++ i++ i {
            int x = i;
            if (x % 3 == 0) {
                sysout.print(" " + i);
                continue;
            }
            while (x > 0) {
                boolean end = false;
                if (x % 10 == 3) {
                    sysout.print(" " + i);
                    end = true;
                }
                if (end) break;
                x /= 10;
            }
        } {
            int x = i;
            if (x % 3 == 0) {
                sysout.print(" " + i);
                continue;
            }
            while (x > 0) {
                boolean end = false;
                if (x % 10 == 3) {
                    sysout.print(" " + i);
                    end = true;
                }
                if (end) break;
                x /= 10;
            }
        } int x = i; x i if (x % 3 == 0) {
                sysout.print(" " + i);
                continue;
            } x % 3 == 0 x % 3 x 3 0 {
                sysout.print(" " + i);
                continue;
            } sysout.print(" " + i) sysout.print sysout " " + i " " i continue; while (x > 0) {
                boolean end = false;
                if (x % 10 == 3) {
                    sysout.print(" " + i);
                    end = true;
                }
                if (end) break;
                x /= 10;
            } x > 0 x 0 {
                boolean end = false;
                if (x % 10 == 3) {
                    sysout.print(" " + i);
                    end = true;
                }
                if (end) break;
                x /= 10;
            } boolean end = false; end false if (x % 10 == 3) {
                    sysout.print(" " + i);
                    end = true;
                } x % 10 == 3 x % 10 x 10 3 {
                    sysout.print(" " + i);
                    end = true;
                } sysout.print(" " + i) sysout.print sysout " " + i " " i end = true end true if (end) break; end break; x /= 10 x 10 sysout.println() sysout.println sysout public static void main(String[] args) {
        new Main().run();
    } main {
        new Main().run();
    } new Main().run() new Main().run new Main() String[] args args String readLine() {
        buffer = null;
        try {
            return in.readLine();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    } readLine {
        buffer = null;
        try {
            return in.readLine();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    } buffer = null buffer null try {
            return in.readLine();
        } catch (IOException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        } IOException e {
            throw new RuntimeException(e);
        } throw new RuntimeException(e); new RuntimeException(e) {
            return in.readLine();
        } return in.readLine(); in.readLine() in.readLine in String read() {
        if (buffer == null || !buffer.hasMoreTokens()) {
            buffer = new StringTokenizer(readLine());
        }
        return buffer.nextToken();
    } read {
        if (buffer == null || !buffer.hasMoreTokens()) {
            buffer = new StringTokenizer(readLine());
        }
        return buffer.nextToken();
    } if (buffer == null || !buffer.hasMoreTokens()) {
            buffer = new StringTokenizer(readLine());
        } buffer == null || !buffer.hasMoreTokens() buffer == null buffer null !buffer.hasMoreTokens() buffer.hasMoreTokens() buffer.hasMoreTokens buffer {
            buffer = new StringTokenizer(readLine());
        } buffer = new StringTokenizer(readLine()) buffer new StringTokenizer(readLine()) return buffer.nextToken(); buffer.nextToken() buffer.nextToken buffer int readInt() {
        return Integer.parseInt(read());
    } readInt {
        return Integer.parseInt(read());
    } return Integer.parseInt(read()); Integer.parseInt(read()) Integer.parseInt Integer read() read long readLong() {
        return Long.parseLong(read());
    } readLong {
        return Long.parseLong(read());
    } return Long.parseLong(read()); Long.parseLong(read()) Long.parseLong Long read() read double readDouble() {
        return Double.parseDouble(read());
    } readDouble {
        return Double.parseDouble(read());
    } return Double.parseDouble(read()); Double.parseDouble(read()) Double.parseDouble Double read() read public class Main {
    void run() {
        int N = readInt();
        for (int i = 1; i <= N; i++) {
            int x = i;
            if (x % 3 == 0) {
                sysout.print(" " + i);
                continue;
            }
            while (x > 0) {
                boolean end = false;
                if (x % 10 == 3) {
                    sysout.print(" " + i);
                    end = true;
                }
                if (end) break;
                x /= 10;
            }
        }
        sysout.println();
    }

    public static void main(String[] args) {
        new Main().run();
    }

    // flush automatically iff you call `println` or `printf` or `format`.
    PrintWriter sysout = new PrintWriter(System.out, true);

    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer buffer = null;

    String readLine() {
        buffer = null;
        try {
            return in.readLine();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    String read() {
        if (buffer == null || !buffer.hasMoreTokens()) {
            buffer = new StringTokenizer(readLine());
        }
        return buffer.nextToken();
    }

    int readInt() {
        return Integer.parseInt(read());
    }

    long readLong() {
        return Long.parseLong(read());
    }

    double readDouble() {
        return Double.parseDouble(read());
    }
} public class Main {
    void run() {
        int N = readInt();
        for (int i = 1; i <= N; i++) {
            int x = i;
            if (x % 3 == 0) {
                sysout.print(" " + i);
                continue;
            }
            while (x > 0) {
                boolean end = false;
                if (x % 10 == 3) {
                    sysout.print(" " + i);
                    end = true;
                }
                if (end) break;
                x /= 10;
            }
        }
        sysout.println();
    }

    public static void main(String[] args) {
        new Main().run();
    }

    // flush automatically iff you call `println` or `printf` or `format`.
    PrintWriter sysout = new PrintWriter(System.out, true);

    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer buffer = null;

    String readLine() {
        buffer = null;
        try {
            return in.readLine();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    String read() {
        if (buffer == null || !buffer.hasMoreTokens()) {
            buffer = new StringTokenizer(readLine());
        }
        return buffer.nextToken();
    }

    int readInt() {
        return Integer.parseInt(read());
    }

    long readLong() {
        return Long.parseLong(read());
    }

    double readDouble() {
        return Double.parseDouble(read());
    }
} Main
import java.io.*;
import java.util.*;

public class Main {
    void run() {
        int N = readInt();
        for (int i = 1; i <= N; i++) {
            int x = i;
            if (x % 3 == 0) {
                sysout.print(" " + i);
                continue;
            }
            while (x > 0) {
                boolean end = false;
                if (x % 10 == 3) {
                    sysout.print(" " + i);
                    end = true;
                }
                if (end) break;
                x /= 10;
            }
        }
        sysout.println();
    }

    public static void main(String[] args) {
        new Main().run();
    }

    // flush automatically iff you call `println` or `printf` or `format`.
    PrintWriter sysout = new PrintWriter(System.out, true);

    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer buffer = null;

    String readLine() {
        buffer = null;
        try {
            return in.readLine();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    String read() {
        if (buffer == null || !buffer.hasMoreTokens()) {
            buffer = new StringTokenizer(readLine());
        }
        return buffer.nextToken();
    }

    int readInt() {
        return Integer.parseInt(read());
    }

    long readLong() {
        return Long.parseLong(read());
    }

    double readDouble() {
        return Double.parseDouble(read());
    }
}