import java.io.*;
import java.util.*;

public class Main {
    
    static int check_three2(int num){
        if (num < 10 && num !=3)return 0;
        int temp = num - (num / 10 * 10);
        if (temp == 3){
            return 1;
        }else{
            return check_three2((num-temp)/10);
        }
    }
    
    
    static int check_three(int num){
        if (num % 3 == 0){
            return 1;
        }else{
            if  (check_three2(num) == 1){
                return 1;
            }
            return 0;
        }
    }    

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int N = in.nextInt();
        
        for (int i = 1; i <= N; i++){
            if (check_three(i) == 1){
                System.out.print(" " + i);
            }
        }
        System.out.println("");
        
    }
} import java.io.*; io.* java import java.util.*; util.* java public class Main {
    
    static int check_three2(int num){
        if (num < 10 && num !=3)return 0;
        int temp = num - (num / 10 * 10);
        if (temp == 3){
            return 1;
        }else{
            return check_three2((num-temp)/10);
        }
    }
    
    
    static int check_three(int num){
        if (num % 3 == 0){
            return 1;
        }else{
            if  (check_three2(num) == 1){
                return 1;
            }
            return 0;
        }
    }    

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int N = in.nextInt();
        
        for (int i = 1; i <= N; i++){
            if (check_three(i) == 1){
                System.out.print(" " + i);
            }
        }
        System.out.println("");
        
    }
} Main static int check_three2(int num){
        if (num < 10 && num !=3)return 0;
        int temp = num - (num / 10 * 10);
        if (temp == 3){
            return 1;
        }else{
            return check_three2((num-temp)/10);
        }
    } check_three2 {
        if (num < 10 && num !=3)return 0;
        int temp = num - (num / 10 * 10);
        if (temp == 3){
            return 1;
        }else{
            return check_three2((num-temp)/10);
        }
    } if (num < 10 && num !=3)return 0; num < 10 && num !=3 num < 10 num 10 num !=3 num 3 return 0; 0 int temp = num - (num / 10 * 10); temp num - (num / 10 * 10) num (num / 10 * 10) num / 10 num 10 10 if (temp == 3){
            return 1;
        }else{
            return check_three2((num-temp)/10);
        } temp == 3 temp 3 {
            return 1;
        } return 1; 1 {
            return check_three2((num-temp)/10);
        } return check_three2((num-temp)/10); check_three2((num-temp)/10) check_three2 (num-temp)/10 (num-temp) num temp 10 int num num static int check_three(int num){
        if (num % 3 == 0){
            return 1;
        }else{
            if  (check_three2(num) == 1){
                return 1;
            }
            return 0;
        }
    } check_three {
        if (num % 3 == 0){
            return 1;
        }else{
            if  (check_three2(num) == 1){
                return 1;
            }
            return 0;
        }
    } if (num % 3 == 0){
            return 1;
        }else{
            if  (check_three2(num) == 1){
                return 1;
            }
            return 0;
        } num % 3 == 0 num % 3 num 3 0 {
            return 1;
        } return 1; 1 {
            if  (check_three2(num) == 1){
                return 1;
            }
            return 0;
        } if  (check_three2(num) == 1){
                return 1;
            } check_three2(num) == 1 check_three2(num) check_three2 num 1 {
                return 1;
            } return 1; 1 return 0; 0 int num num public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int N = in.nextInt();
        
        for (int i = 1; i <= N; i++){
            if (check_three(i) == 1){
                System.out.print(" " + i);
            }
        }
        System.out.println("");
        
    } main {
        Scanner in = new Scanner(System.in);
        int N = in.nextInt();
        
        for (int i = 1; i <= N; i++){
            if (check_three(i) == 1){
                System.out.print(" " + i);
            }
        }
        System.out.println("");
        
    } Scanner in = new Scanner(System.in); in new Scanner(System.in) int N = in.nextInt(); N in.nextInt() in.nextInt in for (int i = 1; i <= N; i++){
            if (check_three(i) == 1){
                System.out.print(" " + i);
            }
        } int i = 1; int i = 1; i 1 i <= N i N i++ i++ i {
            if (check_three(i) == 1){
                System.out.print(" " + i);
            }
        } {
            if (check_three(i) == 1){
                System.out.print(" " + i);
            }
        } if (check_three(i) == 1){
                System.out.print(" " + i);
            } check_three(i) == 1 check_three(i) check_three i 1 {
                System.out.print(" " + i);
            } System.out.print(" " + i) System.out.print System.out System System.out " " + i " " i System.out.println("") System.out.println System.out System System.out "" String[] args args public class Main {
    
    static int check_three2(int num){
        if (num < 10 && num !=3)return 0;
        int temp = num - (num / 10 * 10);
        if (temp == 3){
            return 1;
        }else{
            return check_three2((num-temp)/10);
        }
    }
    
    
    static int check_three(int num){
        if (num % 3 == 0){
            return 1;
        }else{
            if  (check_three2(num) == 1){
                return 1;
            }
            return 0;
        }
    }    

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int N = in.nextInt();
        
        for (int i = 1; i <= N; i++){
            if (check_three(i) == 1){
                System.out.print(" " + i);
            }
        }
        System.out.println("");
        
    }
} public class Main {
    
    static int check_three2(int num){
        if (num < 10 && num !=3)return 0;
        int temp = num - (num / 10 * 10);
        if (temp == 3){
            return 1;
        }else{
            return check_three2((num-temp)/10);
        }
    }
    
    
    static int check_three(int num){
        if (num % 3 == 0){
            return 1;
        }else{
            if  (check_three2(num) == 1){
                return 1;
            }
            return 0;
        }
    }    

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int N = in.nextInt();
        
        for (int i = 1; i <= N; i++){
            if (check_three(i) == 1){
                System.out.print(" " + i);
            }
        }
        System.out.println("");
        
    }
} Main
import java.io.*;
import java.util.*;

public class Main {
    
    static int check_three2(int num){
        if (num < 10 && num !=3)return 0;
        int temp = num - (num / 10 * 10);
        if (temp == 3){
            return 1;
        }else{
            return check_three2((num-temp)/10);
        }
    }
    
    
    static int check_three(int num){
        if (num % 3 == 0){
            return 1;
        }else{
            if  (check_three2(num) == 1){
                return 1;
            }
            return 0;
        }
    }    

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int N = in.nextInt();
        
        for (int i = 1; i <= N; i++){
            if (check_three(i) == 1){
                System.out.print(" " + i);
            }
        }
        System.out.println("");
        
    }
}