import java.io.*;

class Main {
    public static void main (String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        String cout = "";
        int x;
        outside: for (int i = 1; i <= n; i++) {
            x = i;
            if (x % 3 == 0) {
                cout += " " + i;
                continue;
            } else {
                do {
                    if (x % 10 == 3) {
                        cout += " " + i;
                        continue outside;
                    }
                    x /= 10;
                } while (x > 0);
            }
        }
        System.out.println(cout);
    }
} import java.io.*; io.* java class Main {
    public static void main (String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        String cout = "";
        int x;
        outside: for (int i = 1; i <= n; i++) {
            x = i;
            if (x % 3 == 0) {
                cout += " " + i;
                continue;
            } else {
                do {
                    if (x % 10 == 3) {
                        cout += " " + i;
                        continue outside;
                    }
                    x /= 10;
                } while (x > 0);
            }
        }
        System.out.println(cout);
    }
} Main public static void main (String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        String cout = "";
        int x;
        outside: for (int i = 1; i <= n; i++) {
            x = i;
            if (x % 3 == 0) {
                cout += " " + i;
                continue;
            } else {
                do {
                    if (x % 10 == 3) {
                        cout += " " + i;
                        continue outside;
                    }
                    x /= 10;
                } while (x > 0);
            }
        }
        System.out.println(cout);
    } main {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        String cout = "";
        int x;
        outside: for (int i = 1; i <= n; i++) {
            x = i;
            if (x % 3 == 0) {
                cout += " " + i;
                continue;
            } else {
                do {
                    if (x % 10 == 3) {
                        cout += " " + i;
                        continue outside;
                    }
                    x /= 10;
                } while (x > 0);
            }
        }
        System.out.println(cout);
    } 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 String cout = ""; cout "" int x; x System.out.println(cout) System.out.println System.out System System.out cout String[] args args
import java.io.*;

class Main {
    public static void main (String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        String cout = "";
        int x;
        outside: for (int i = 1; i <= n; i++) {
            x = i;
            if (x % 3 == 0) {
                cout += " " + i;
                continue;
            } else {
                do {
                    if (x % 10 == 3) {
                        cout += " " + i;
                        continue outside;
                    }
                    x /= 10;
                } while (x > 0);
            }
        }
        System.out.println(cout);
    }
}