import java.util.Scanner;
 
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        StringBuilder sb = new StringBuilder();
        
        int n = sc.nextInt();
        for (int i = 3; i <= n; i++) {
            if (i%3 == 0) {
                sb.append(" ").append(i);
            } 
            else  {
                int j = i;
                while (j != 0) {
                    if (j%10 == 3) {
                        sb.append(" ").append(i);
                        break;
                    }
                    j /= 10;
                }
            }
        }
        System.out.println(sb);
    }
} import java.util.Scanner; Scanner java.util class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        StringBuilder sb = new StringBuilder();
        
        int n = sc.nextInt();
        for (int i = 3; i <= n; i++) {
            if (i%3 == 0) {
                sb.append(" ").append(i);
            } 
            else  {
                int j = i;
                while (j != 0) {
                    if (j%10 == 3) {
                        sb.append(" ").append(i);
                        break;
                    }
                    j /= 10;
                }
            }
        }
        System.out.println(sb);
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        StringBuilder sb = new StringBuilder();
        
        int n = sc.nextInt();
        for (int i = 3; i <= n; i++) {
            if (i%3 == 0) {
                sb.append(" ").append(i);
            } 
            else  {
                int j = i;
                while (j != 0) {
                    if (j%10 == 3) {
                        sb.append(" ").append(i);
                        break;
                    }
                    j /= 10;
                }
            }
        }
        System.out.println(sb);
    } main {
        Scanner sc = new Scanner(System.in);
        StringBuilder sb = new StringBuilder();
        
        int n = sc.nextInt();
        for (int i = 3; i <= n; i++) {
            if (i%3 == 0) {
                sb.append(" ").append(i);
            } 
            else  {
                int j = i;
                while (j != 0) {
                    if (j%10 == 3) {
                        sb.append(" ").append(i);
                        break;
                    }
                    j /= 10;
                }
            }
        }
        System.out.println(sb);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) StringBuilder sb = new StringBuilder(); sb new StringBuilder() int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc for (int i = 3; i <= n; i++) {
            if (i%3 == 0) {
                sb.append(" ").append(i);
            } 
            else  {
                int j = i;
                while (j != 0) {
                    if (j%10 == 3) {
                        sb.append(" ").append(i);
                        break;
                    }
                    j /= 10;
                }
            }
        } int i = 3; int i = 3; i 3 i <= n i n i++ i++ i {
            if (i%3 == 0) {
                sb.append(" ").append(i);
            } 
            else  {
                int j = i;
                while (j != 0) {
                    if (j%10 == 3) {
                        sb.append(" ").append(i);
                        break;
                    }
                    j /= 10;
                }
            }
        } {
            if (i%3 == 0) {
                sb.append(" ").append(i);
            } 
            else  {
                int j = i;
                while (j != 0) {
                    if (j%10 == 3) {
                        sb.append(" ").append(i);
                        break;
                    }
                    j /= 10;
                }
            }
        } if (i%3 == 0) {
                sb.append(" ").append(i);
            } 
            else  {
                int j = i;
                while (j != 0) {
                    if (j%10 == 3) {
                        sb.append(" ").append(i);
                        break;
                    }
                    j /= 10;
                }
            } i%3 == 0 i%3 i 3 0 {
                sb.append(" ").append(i);
            } sb.append(" ").append(i) sb.append(" ").append sb.append(" ") sb.append sb " " i {
                int j = i;
                while (j != 0) {
                    if (j%10 == 3) {
                        sb.append(" ").append(i);
                        break;
                    }
                    j /= 10;
                }
            } int j = i; j i while (j != 0) {
                    if (j%10 == 3) {
                        sb.append(" ").append(i);
                        break;
                    }
                    j /= 10;
                } j != 0 j 0 {
                    if (j%10 == 3) {
                        sb.append(" ").append(i);
                        break;
                    }
                    j /= 10;
                } if (j%10 == 3) {
                        sb.append(" ").append(i);
                        break;
                    } j%10 == 3 j%10 j 10 3 {
                        sb.append(" ").append(i);
                        break;
                    } sb.append(" ").append(i) sb.append(" ").append sb.append(" ") sb.append sb " " i break; j /= 10 j 10 System.out.println(sb) System.out.println System.out System System.out sb String[] args args
import java.util.Scanner;
 
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        StringBuilder sb = new StringBuilder();
        
        int n = sc.nextInt();
        for (int i = 3; i <= n; i++) {
            if (i%3 == 0) {
                sb.append(" ").append(i);
            } 
            else  {
                int j = i;
                while (j != 0) {
                    if (j%10 == 3) {
                        sb.append(" ").append(i);
                        break;
                    }
                    j /= 10;
                }
            }
        }
        System.out.println(sb);
    }
}