import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int x;
        for (int i = 1; i <= n; i++) {
            x = i;
            if (checkNum(x, i)) continue;
            include3(x, i);
        }

        System.out.println("");

        sc.close();
    }

    static boolean checkNum(int x, int i) {
        if ((x % 3) != 0) return false;
        System.out.printf(" %d", i);
        return true;
    }

    static void include3(int x, int i) {
        if ((x % 10) == 3) {
            System.out.printf(" %d", i);
            return;
        }

        x /= 10;
        if (x != 0) include3(x, i);
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int x;
        for (int i = 1; i <= n; i++) {
            x = i;
            if (checkNum(x, i)) continue;
            include3(x, i);
        }

        System.out.println("");

        sc.close();
    }

    static boolean checkNum(int x, int i) {
        if ((x % 3) != 0) return false;
        System.out.printf(" %d", i);
        return true;
    }

    static void include3(int x, int i) {
        if ((x % 10) == 3) {
            System.out.printf(" %d", i);
            return;
        }

        x /= 10;
        if (x != 0) include3(x, i);
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int x;
        for (int i = 1; i <= n; i++) {
            x = i;
            if (checkNum(x, i)) continue;
            include3(x, i);
        }

        System.out.println("");

        sc.close();
    } main {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int x;
        for (int i = 1; i <= n; i++) {
            x = i;
            if (checkNum(x, i)) continue;
            include3(x, i);
        }

        System.out.println("");

        sc.close();
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int x; x for (int i = 1; i <= n; i++) {
            x = i;
            if (checkNum(x, i)) continue;
            include3(x, i);
        } int i = 1; int i = 1; i 1 i <= n i n i++ i++ i {
            x = i;
            if (checkNum(x, i)) continue;
            include3(x, i);
        } {
            x = i;
            if (checkNum(x, i)) continue;
            include3(x, i);
        } x = i x i if (checkNum(x, i)) continue; checkNum(x, i) checkNum x i continue; include3(x, i) include3 x i System.out.println("") System.out.println System.out System System.out "" sc.close() sc.close sc String[] args args static boolean checkNum(int x, int i) {
        if ((x % 3) != 0) return false;
        System.out.printf(" %d", i);
        return true;
    } checkNum {
        if ((x % 3) != 0) return false;
        System.out.printf(" %d", i);
        return true;
    } if ((x % 3) != 0) return false; (x % 3) != 0 (x % 3) x 3 0 return false; false System.out.printf(" %d", i) System.out.printf System.out System System.out " %d" i return true; true int x x int i i static void include3(int x, int i) {
        if ((x % 10) == 3) {
            System.out.printf(" %d", i);
            return;
        }

        x /= 10;
        if (x != 0) include3(x, i);
    } include3 {
        if ((x % 10) == 3) {
            System.out.printf(" %d", i);
            return;
        }

        x /= 10;
        if (x != 0) include3(x, i);
    } if ((x % 10) == 3) {
            System.out.printf(" %d", i);
            return;
        } (x % 10) == 3 (x % 10) x 10 3 {
            System.out.printf(" %d", i);
            return;
        } System.out.printf(" %d", i) System.out.printf System.out System System.out " %d" i return; x /= 10 x 10 if (x != 0) include3(x, i); x != 0 x 0 include3(x, i) include3 x i int x x int i i public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int x;
        for (int i = 1; i <= n; i++) {
            x = i;
            if (checkNum(x, i)) continue;
            include3(x, i);
        }

        System.out.println("");

        sc.close();
    }

    static boolean checkNum(int x, int i) {
        if ((x % 3) != 0) return false;
        System.out.printf(" %d", i);
        return true;
    }

    static void include3(int x, int i) {
        if ((x % 10) == 3) {
            System.out.printf(" %d", i);
            return;
        }

        x /= 10;
        if (x != 0) include3(x, i);
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int x;
        for (int i = 1; i <= n; i++) {
            x = i;
            if (checkNum(x, i)) continue;
            include3(x, i);
        }

        System.out.println("");

        sc.close();
    }

    static boolean checkNum(int x, int i) {
        if ((x % 3) != 0) return false;
        System.out.printf(" %d", i);
        return true;
    }

    static void include3(int x, int i) {
        if ((x % 10) == 3) {
            System.out.printf(" %d", i);
            return;
        }

        x /= 10;
        if (x != 0) include3(x, i);
    }
} Main
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int x;
        for (int i = 1; i <= n; i++) {
            x = i;
            if (checkNum(x, i)) continue;
            include3(x, i);
        }

        System.out.println("");

        sc.close();
    }

    static boolean checkNum(int x, int i) {
        if ((x % 3) != 0) return false;
        System.out.printf(" %d", i);
        return true;
    }

    static void include3(int x, int i) {
        if ((x % 10) == 3) {
            System.out.printf(" %d", i);
            return;
        }

        x /= 10;
        if (x != 0) include3(x, i);
    }
}
