import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {
        Scanner input = new Scanner(System.in);
        StringBuilder build = new StringBuilder();
        int n = input.nextInt();
        for(int i = 1; i <= n; i++){
            if(i%3 == 0 || i%10 == 3){
                build.append(" "+i);
                continue;
            }
            int x = i;
            while(true){
                x /= 10;
                if(x%10 == 3){
                    build.append(" "+i);
                    break;
                }
                if(x <= 3){
                    break;
                }
            }
        }
        System.out.println(build);
    }
} import java.util.Scanner; Scanner java.util public class Main {

    public static void main(String[] args) throws Exception {
        Scanner input = new Scanner(System.in);
        StringBuilder build = new StringBuilder();
        int n = input.nextInt();
        for(int i = 1; i <= n; i++){
            if(i%3 == 0 || i%10 == 3){
                build.append(" "+i);
                continue;
            }
            int x = i;
            while(true){
                x /= 10;
                if(x%10 == 3){
                    build.append(" "+i);
                    break;
                }
                if(x <= 3){
                    break;
                }
            }
        }
        System.out.println(build);
    }
} Main public static void main(String[] args) throws Exception {
        Scanner input = new Scanner(System.in);
        StringBuilder build = new StringBuilder();
        int n = input.nextInt();
        for(int i = 1; i <= n; i++){
            if(i%3 == 0 || i%10 == 3){
                build.append(" "+i);
                continue;
            }
            int x = i;
            while(true){
                x /= 10;
                if(x%10 == 3){
                    build.append(" "+i);
                    break;
                }
                if(x <= 3){
                    break;
                }
            }
        }
        System.out.println(build);
    } main {
        Scanner input = new Scanner(System.in);
        StringBuilder build = new StringBuilder();
        int n = input.nextInt();
        for(int i = 1; i <= n; i++){
            if(i%3 == 0 || i%10 == 3){
                build.append(" "+i);
                continue;
            }
            int x = i;
            while(true){
                x /= 10;
                if(x%10 == 3){
                    build.append(" "+i);
                    break;
                }
                if(x <= 3){
                    break;
                }
            }
        }
        System.out.println(build);
    } Scanner input = new Scanner(System.in); input new Scanner(System.in) StringBuilder build = new StringBuilder(); build new StringBuilder() int n = input.nextInt(); n input.nextInt() input.nextInt input for(int i = 1; i <= n; i++){
            if(i%3 == 0 || i%10 == 3){
                build.append(" "+i);
                continue;
            }
            int x = i;
            while(true){
                x /= 10;
                if(x%10 == 3){
                    build.append(" "+i);
                    break;
                }
                if(x <= 3){
                    break;
                }
            }
        } int i = 1; int i = 1; i 1 i <= n i n i++ i++ i {
            if(i%3 == 0 || i%10 == 3){
                build.append(" "+i);
                continue;
            }
            int x = i;
            while(true){
                x /= 10;
                if(x%10 == 3){
                    build.append(" "+i);
                    break;
                }
                if(x <= 3){
                    break;
                }
            }
        } {
            if(i%3 == 0 || i%10 == 3){
                build.append(" "+i);
                continue;
            }
            int x = i;
            while(true){
                x /= 10;
                if(x%10 == 3){
                    build.append(" "+i);
                    break;
                }
                if(x <= 3){
                    break;
                }
            }
        } if(i%3 == 0 || i%10 == 3){
                build.append(" "+i);
                continue;
            } i%3 == 0 || i%10 == 3 i%3 == 0 i%3 i 3 0 i%10 == 3 i%10 i 10 3 {
                build.append(" "+i);
                continue;
            } build.append(" "+i) build.append build " "+i " " i continue; int x = i; x i while(true){
                x /= 10;
                if(x%10 == 3){
                    build.append(" "+i);
                    break;
                }
                if(x <= 3){
                    break;
                }
            } true {
                x /= 10;
                if(x%10 == 3){
                    build.append(" "+i);
                    break;
                }
                if(x <= 3){
                    break;
                }
            } x /= 10 x 10 if(x%10 == 3){
                    build.append(" "+i);
                    break;
                } x%10 == 3 x%10 x 10 3 {
                    build.append(" "+i);
                    break;
                } build.append(" "+i) build.append build " "+i " " i break; if(x <= 3){
                    break;
                } x <= 3 x 3 {
                    break;
                } break; System.out.println(build) System.out.println System.out System System.out build String[] args args public class Main {

    public static void main(String[] args) throws Exception {
        Scanner input = new Scanner(System.in);
        StringBuilder build = new StringBuilder();
        int n = input.nextInt();
        for(int i = 1; i <= n; i++){
            if(i%3 == 0 || i%10 == 3){
                build.append(" "+i);
                continue;
            }
            int x = i;
            while(true){
                x /= 10;
                if(x%10 == 3){
                    build.append(" "+i);
                    break;
                }
                if(x <= 3){
                    break;
                }
            }
        }
        System.out.println(build);
    }
} public class Main {

    public static void main(String[] args) throws Exception {
        Scanner input = new Scanner(System.in);
        StringBuilder build = new StringBuilder();
        int n = input.nextInt();
        for(int i = 1; i <= n; i++){
            if(i%3 == 0 || i%10 == 3){
                build.append(" "+i);
                continue;
            }
            int x = i;
            while(true){
                x /= 10;
                if(x%10 == 3){
                    build.append(" "+i);
                    break;
                }
                if(x <= 3){
                    break;
                }
            }
        }
        System.out.println(build);
    }
} Main
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {
        Scanner input = new Scanner(System.in);
        StringBuilder build = new StringBuilder();
        int n = input.nextInt();
        for(int i = 1; i <= n; i++){
            if(i%3 == 0 || i%10 == 3){
                build.append(" "+i);
                continue;
            }
            int x = i;
            while(true){
                x /= 10;
                if(x%10 == 3){
                    build.append(" "+i);
                    break;
                }
                if(x <= 3){
                    break;
                }
            }
        }
        System.out.println(build);
    }
}