import static java.lang.System.out;
import java.util.Scanner;

class Main{
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        for(int i = 3; i <= n; i++) {
            if (i % 3 == 0 || i % 10 == 3 || i / 10 == 3) {
                out.print(" " + i);
            } else {
                int num = i;
                while(i >= 100) {
                    i = i / 10;
                    if(i % 10 == 3 || i / 10 == 3) {                            
                        out.print(" " + num);
                        break;
                    }
                }
                i = num;
            }
        }
        out.println();
    }
} import static java.lang.System.out; import static java.lang.System.out; import static java.lang.System.out; import java.util.Scanner; Scanner java.util class Main{
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        for(int i = 3; i <= n; i++) {
            if (i % 3 == 0 || i % 10 == 3 || i / 10 == 3) {
                out.print(" " + i);
            } else {
                int num = i;
                while(i >= 100) {
                    i = i / 10;
                    if(i % 10 == 3 || i / 10 == 3) {                            
                        out.print(" " + num);
                        break;
                    }
                }
                i = num;
            }
        }
        out.println();
    }
} Main public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        for(int i = 3; i <= n; i++) {
            if (i % 3 == 0 || i % 10 == 3 || i / 10 == 3) {
                out.print(" " + i);
            } else {
                int num = i;
                while(i >= 100) {
                    i = i / 10;
                    if(i % 10 == 3 || i / 10 == 3) {                            
                        out.print(" " + num);
                        break;
                    }
                }
                i = num;
            }
        }
        out.println();
    } main {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        for(int i = 3; i <= n; i++) {
            if (i % 3 == 0 || i % 10 == 3 || i / 10 == 3) {
                out.print(" " + i);
            } else {
                int num = i;
                while(i >= 100) {
                    i = i / 10;
                    if(i % 10 == 3 || i / 10 == 3) {                            
                        out.print(" " + num);
                        break;
                    }
                }
                i = num;
            }
        }
        out.println();
    } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan for(int i = 3; i <= n; i++) {
            if (i % 3 == 0 || i % 10 == 3 || i / 10 == 3) {
                out.print(" " + i);
            } else {
                int num = i;
                while(i >= 100) {
                    i = i / 10;
                    if(i % 10 == 3 || i / 10 == 3) {                            
                        out.print(" " + num);
                        break;
                    }
                }
                i = num;
            }
        } int i = 3; int i = 3; i 3 i <= n i n i++ i++ i {
            if (i % 3 == 0 || i % 10 == 3 || i / 10 == 3) {
                out.print(" " + i);
            } else {
                int num = i;
                while(i >= 100) {
                    i = i / 10;
                    if(i % 10 == 3 || i / 10 == 3) {                            
                        out.print(" " + num);
                        break;
                    }
                }
                i = num;
            }
        } {
            if (i % 3 == 0 || i % 10 == 3 || i / 10 == 3) {
                out.print(" " + i);
            } else {
                int num = i;
                while(i >= 100) {
                    i = i / 10;
                    if(i % 10 == 3 || i / 10 == 3) {                            
                        out.print(" " + num);
                        break;
                    }
                }
                i = num;
            }
        } if (i % 3 == 0 || i % 10 == 3 || i / 10 == 3) {
                out.print(" " + i);
            } else {
                int num = i;
                while(i >= 100) {
                    i = i / 10;
                    if(i % 10 == 3 || i / 10 == 3) {                            
                        out.print(" " + num);
                        break;
                    }
                }
                i = num;
            } i % 3 == 0 || i % 10 == 3 || i / 10 == 3 i % 3 == 0 || i % 10 == 3 || i / 10 == 3 i % 3 == 0 i % 3 i 3 0 i % 10 == 3 i % 10 i 10 3 i / 10 == 3 i / 10 i 10 3 {
                out.print(" " + i);
            } out.print(" " + i) out.print out " " + i " " i {
                int num = i;
                while(i >= 100) {
                    i = i / 10;
                    if(i % 10 == 3 || i / 10 == 3) {                            
                        out.print(" " + num);
                        break;
                    }
                }
                i = num;
            } int num = i; num i while(i >= 100) {
                    i = i / 10;
                    if(i % 10 == 3 || i / 10 == 3) {                            
                        out.print(" " + num);
                        break;
                    }
                } i >= 100 i 100 {
                    i = i / 10;
                    if(i % 10 == 3 || i / 10 == 3) {                            
                        out.print(" " + num);
                        break;
                    }
                } i = i / 10 i i / 10 i 10 if(i % 10 == 3 || i / 10 == 3) {                            
                        out.print(" " + num);
                        break;
                    } i % 10 == 3 || i / 10 == 3 i % 10 == 3 i % 10 i 10 3 i / 10 == 3 i / 10 i 10 3 {                            
                        out.print(" " + num);
                        break;
                    } out.print(" " + num) out.print out " " + num " " num break; i = num i num out.println() out.println out String[] args args
import static java.lang.System.out;
import java.util.Scanner;

class Main{
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        for(int i = 3; i <= n; i++) {
            if (i % 3 == 0 || i % 10 == 3 || i / 10 == 3) {
                out.print(" " + i);
            } else {
                int num = i;
                while(i >= 100) {
                    i = i / 10;
                    if(i % 10 == 3 || i / 10 == 3) {                            
                        out.print(" " + num);
                        break;
                    }
                }
                i = num;
            }
        }
        out.println();
    }
}