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

public class Main {
    public static void main(String[] args) throws Exception {
        // Here your code !
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        call(Integer.parseInt(line));

    }
    static void call(int n) {
        for(int i=1;i <= n;i++) {
            int x = i;
            if(x % 3 == 0){
                System.out.print(" " + i);
                continue;
                
            }
            while(true) {
                if(x % 10 == 3) {
                    System.out.print(" " + i);
                    break;
                }
                x = x / 10;
                if(x != 0) {
                    continue;
                }else {
                    break;
                }
            }
        }
        System.out.println();

    }
} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {
    public static void main(String[] args) throws Exception {
        // Here your code !
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        call(Integer.parseInt(line));

    }
    static void call(int n) {
        for(int i=1;i <= n;i++) {
            int x = i;
            if(x % 3 == 0){
                System.out.print(" " + i);
                continue;
                
            }
            while(true) {
                if(x % 10 == 3) {
                    System.out.print(" " + i);
                    break;
                }
                x = x / 10;
                if(x != 0) {
                    continue;
                }else {
                    break;
                }
            }
        }
        System.out.println();

    }
} Main public static void main(String[] args) throws Exception {
        // Here your code !
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        call(Integer.parseInt(line));

    } main {
        // Here your code !
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        call(Integer.parseInt(line));

    } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String line = br.readLine(); line br.readLine() br.readLine br call(Integer.parseInt(line)) call Integer.parseInt(line) Integer.parseInt Integer line String[] args args static void call(int n) {
        for(int i=1;i <= n;i++) {
            int x = i;
            if(x % 3 == 0){
                System.out.print(" " + i);
                continue;
                
            }
            while(true) {
                if(x % 10 == 3) {
                    System.out.print(" " + i);
                    break;
                }
                x = x / 10;
                if(x != 0) {
                    continue;
                }else {
                    break;
                }
            }
        }
        System.out.println();

    } call {
        for(int i=1;i <= n;i++) {
            int x = i;
            if(x % 3 == 0){
                System.out.print(" " + i);
                continue;
                
            }
            while(true) {
                if(x % 10 == 3) {
                    System.out.print(" " + i);
                    break;
                }
                x = x / 10;
                if(x != 0) {
                    continue;
                }else {
                    break;
                }
            }
        }
        System.out.println();

    } for(int i=1;i <= n;i++) {
            int x = i;
            if(x % 3 == 0){
                System.out.print(" " + i);
                continue;
                
            }
            while(true) {
                if(x % 10 == 3) {
                    System.out.print(" " + i);
                    break;
                }
                x = x / 10;
                if(x != 0) {
                    continue;
                }else {
                    break;
                }
            }
        } int i=1; int i=1; i 1 i <= n i n i++ i++ i {
            int x = i;
            if(x % 3 == 0){
                System.out.print(" " + i);
                continue;
                
            }
            while(true) {
                if(x % 10 == 3) {
                    System.out.print(" " + i);
                    break;
                }
                x = x / 10;
                if(x != 0) {
                    continue;
                }else {
                    break;
                }
            }
        } {
            int x = i;
            if(x % 3 == 0){
                System.out.print(" " + i);
                continue;
                
            }
            while(true) {
                if(x % 10 == 3) {
                    System.out.print(" " + i);
                    break;
                }
                x = x / 10;
                if(x != 0) {
                    continue;
                }else {
                    break;
                }
            }
        } int x = i; x i if(x % 3 == 0){
                System.out.print(" " + i);
                continue;
                
            } x % 3 == 0 x % 3 x 3 0 {
                System.out.print(" " + i);
                continue;
                
            } System.out.print(" " + i) System.out.print System.out System System.out " " + i " " i continue; while(true) {
                if(x % 10 == 3) {
                    System.out.print(" " + i);
                    break;
                }
                x = x / 10;
                if(x != 0) {
                    continue;
                }else {
                    break;
                }
            } true {
                if(x % 10 == 3) {
                    System.out.print(" " + i);
                    break;
                }
                x = x / 10;
                if(x != 0) {
                    continue;
                }else {
                    break;
                }
            } if(x % 10 == 3) {
                    System.out.print(" " + i);
                    break;
                } x % 10 == 3 x % 10 x 10 3 {
                    System.out.print(" " + i);
                    break;
                } System.out.print(" " + i) System.out.print System.out System System.out " " + i " " i break; x = x / 10 x x / 10 x 10 if(x != 0) {
                    continue;
                }else {
                    break;
                } x != 0 x 0 {
                    continue;
                } continue; {
                    break;
                } break; System.out.println() System.out.println System.out System System.out int n n public class Main {
    public static void main(String[] args) throws Exception {
        // Here your code !
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        call(Integer.parseInt(line));

    }
    static void call(int n) {
        for(int i=1;i <= n;i++) {
            int x = i;
            if(x % 3 == 0){
                System.out.print(" " + i);
                continue;
                
            }
            while(true) {
                if(x % 10 == 3) {
                    System.out.print(" " + i);
                    break;
                }
                x = x / 10;
                if(x != 0) {
                    continue;
                }else {
                    break;
                }
            }
        }
        System.out.println();

    }
} public class Main {
    public static void main(String[] args) throws Exception {
        // Here your code !
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        call(Integer.parseInt(line));

    }
    static void call(int n) {
        for(int i=1;i <= n;i++) {
            int x = i;
            if(x % 3 == 0){
                System.out.print(" " + i);
                continue;
                
            }
            while(true) {
                if(x % 10 == 3) {
                    System.out.print(" " + i);
                    break;
                }
                x = x / 10;
                if(x != 0) {
                    continue;
                }else {
                    break;
                }
            }
        }
        System.out.println();

    }
} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws Exception {
        // Here your code !
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        call(Integer.parseInt(line));

    }
    static void call(int n) {
        for(int i=1;i <= n;i++) {
            int x = i;
            if(x % 3 == 0){
                System.out.print(" " + i);
                continue;
                
            }
            while(true) {
                if(x % 10 == 3) {
                    System.out.print(" " + i);
                    break;
                }
                x = x / 10;
                if(x != 0) {
                    continue;
                }else {
                    break;
                }
            }
        }
        System.out.println();

    }
}