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

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        for(int i=3;i<=n;i++){
            if(check(i)){
                System.out.print(" "+i);
            }
        }
        System.out.print("\n");
    }
    public static boolean check(int n){
        if(n%3==0){
            return true;
        }else if(n%10==3){
            return true;
        }else{
            int x = n / 10;
            while(x>0){
                if(x%10==3){
                    return true;
                }
                x = x /10;
            }
            return false;
        }
    } 
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        for(int i=3;i<=n;i++){
            if(check(i)){
                System.out.print(" "+i);
            }
        }
        System.out.print("\n");
    }
    public static boolean check(int n){
        if(n%3==0){
            return true;
        }else if(n%10==3){
            return true;
        }else{
            int x = n / 10;
            while(x>0){
                if(x%10==3){
                    return true;
                }
                x = x /10;
            }
            return false;
        }
    } 
} Main public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        for(int i=3;i<=n;i++){
            if(check(i)){
                System.out.print(" "+i);
            }
        }
        System.out.print("\n");
    } main {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        for(int i=3;i<=n;i++){
            if(check(i)){
                System.out.print(" "+i);
            }
        }
        System.out.print("\n");
    } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) int n = Integer.parseInt(br.readLine()); n Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br for(int i=3;i<=n;i++){
            if(check(i)){
                System.out.print(" "+i);
            }
        } int i=3; int i=3; i 3 i<=n i n i++ i++ i {
            if(check(i)){
                System.out.print(" "+i);
            }
        } {
            if(check(i)){
                System.out.print(" "+i);
            }
        } if(check(i)){
                System.out.print(" "+i);
            } check(i) check i {
                System.out.print(" "+i);
            } System.out.print(" "+i) System.out.print System.out System System.out " "+i " " i System.out.print("\n") System.out.print System.out System System.out "\n" String[] args args public static boolean check(int n){
        if(n%3==0){
            return true;
        }else if(n%10==3){
            return true;
        }else{
            int x = n / 10;
            while(x>0){
                if(x%10==3){
                    return true;
                }
                x = x /10;
            }
            return false;
        }
    } check {
        if(n%3==0){
            return true;
        }else if(n%10==3){
            return true;
        }else{
            int x = n / 10;
            while(x>0){
                if(x%10==3){
                    return true;
                }
                x = x /10;
            }
            return false;
        }
    } if(n%3==0){
            return true;
        }else if(n%10==3){
            return true;
        }else{
            int x = n / 10;
            while(x>0){
                if(x%10==3){
                    return true;
                }
                x = x /10;
            }
            return false;
        } n%3==0 n%3 n 3 0 {
            return true;
        } return true; true if(n%10==3){
            return true;
        }else{
            int x = n / 10;
            while(x>0){
                if(x%10==3){
                    return true;
                }
                x = x /10;
            }
            return false;
        } n%10==3 n%10 n 10 3 {
            return true;
        } return true; true {
            int x = n / 10;
            while(x>0){
                if(x%10==3){
                    return true;
                }
                x = x /10;
            }
            return false;
        } int x = n / 10; x n / 10 n 10 while(x>0){
                if(x%10==3){
                    return true;
                }
                x = x /10;
            } x>0 x 0 {
                if(x%10==3){
                    return true;
                }
                x = x /10;
            } if(x%10==3){
                    return true;
                } x%10==3 x%10 x 10 3 {
                    return true;
                } return true; true x = x /10 x x /10 x 10 return false; false int n n public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        for(int i=3;i<=n;i++){
            if(check(i)){
                System.out.print(" "+i);
            }
        }
        System.out.print("\n");
    }
    public static boolean check(int n){
        if(n%3==0){
            return true;
        }else if(n%10==3){
            return true;
        }else{
            int x = n / 10;
            while(x>0){
                if(x%10==3){
                    return true;
                }
                x = x /10;
            }
            return false;
        }
    } 
} public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        for(int i=3;i<=n;i++){
            if(check(i)){
                System.out.print(" "+i);
            }
        }
        System.out.print("\n");
    }
    public static boolean check(int n){
        if(n%3==0){
            return true;
        }else if(n%10==3){
            return true;
        }else{
            int x = n / 10;
            while(x>0){
                if(x%10==3){
                    return true;
                }
                x = x /10;
            }
            return false;
        }
    } 
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        for(int i=3;i<=n;i++){
            if(check(i)){
                System.out.print(" "+i);
            }
        }
        System.out.print("\n");
    }
    public static boolean check(int n){
        if(n%3==0){
            return true;
        }else if(n%10==3){
            return true;
        }else{
            int x = n / 10;
            while(x>0){
                if(x%10==3){
                    return true;
                }
                x = x /10;
            }
            return false;
        }
    } 
}