import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();
        int a = Integer.parseInt(str);

        if(a >= 3){
            for(int loop = 1; loop <= a; loop++){
                if(loop % 3 == 0) System.out.print(" " + loop);
                else {
                    for(int x = loop; x > 0; x/=10){
                        if(x % 10 == 3) {
                            System.out.print(" " + loop);
                            break;
                        }
                    }
                }
            }
        }
        System.out.println();
    }
} import java.util.Scanner; Scanner java.util public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();
        int a = Integer.parseInt(str);

        if(a >= 3){
            for(int loop = 1; loop <= a; loop++){
                if(loop % 3 == 0) System.out.print(" " + loop);
                else {
                    for(int x = loop; x > 0; x/=10){
                        if(x % 10 == 3) {
                            System.out.print(" " + loop);
                            break;
                        }
                    }
                }
            }
        }
        System.out.println();
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();
        int a = Integer.parseInt(str);

        if(a >= 3){
            for(int loop = 1; loop <= a; loop++){
                if(loop % 3 == 0) System.out.print(" " + loop);
                else {
                    for(int x = loop; x > 0; x/=10){
                        if(x % 10 == 3) {
                            System.out.print(" " + loop);
                            break;
                        }
                    }
                }
            }
        }
        System.out.println();
    } main {
        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();
        int a = Integer.parseInt(str);

        if(a >= 3){
            for(int loop = 1; loop <= a; loop++){
                if(loop % 3 == 0) System.out.print(" " + loop);
                else {
                    for(int x = loop; x > 0; x/=10){
                        if(x % 10 == 3) {
                            System.out.print(" " + loop);
                            break;
                        }
                    }
                }
            }
        }
        System.out.println();
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String str = sc.nextLine(); str sc.nextLine() sc.nextLine sc int a = Integer.parseInt(str); a Integer.parseInt(str) Integer.parseInt Integer str if(a >= 3){
            for(int loop = 1; loop <= a; loop++){
                if(loop % 3 == 0) System.out.print(" " + loop);
                else {
                    for(int x = loop; x > 0; x/=10){
                        if(x % 10 == 3) {
                            System.out.print(" " + loop);
                            break;
                        }
                    }
                }
            }
        } a >= 3 a 3 {
            for(int loop = 1; loop <= a; loop++){
                if(loop % 3 == 0) System.out.print(" " + loop);
                else {
                    for(int x = loop; x > 0; x/=10){
                        if(x % 10 == 3) {
                            System.out.print(" " + loop);
                            break;
                        }
                    }
                }
            }
        } for(int loop = 1; loop <= a; loop++){
                if(loop % 3 == 0) System.out.print(" " + loop);
                else {
                    for(int x = loop; x > 0; x/=10){
                        if(x % 10 == 3) {
                            System.out.print(" " + loop);
                            break;
                        }
                    }
                }
            } int loop = 1; int loop = 1; loop 1 loop <= a loop a loop++ loop++ loop {
                if(loop % 3 == 0) System.out.print(" " + loop);
                else {
                    for(int x = loop; x > 0; x/=10){
                        if(x % 10 == 3) {
                            System.out.print(" " + loop);
                            break;
                        }
                    }
                }
            } {
                if(loop % 3 == 0) System.out.print(" " + loop);
                else {
                    for(int x = loop; x > 0; x/=10){
                        if(x % 10 == 3) {
                            System.out.print(" " + loop);
                            break;
                        }
                    }
                }
            } if(loop % 3 == 0) System.out.print(" " + loop);
                else {
                    for(int x = loop; x > 0; x/=10){
                        if(x % 10 == 3) {
                            System.out.print(" " + loop);
                            break;
                        }
                    }
                } loop % 3 == 0 loop % 3 loop 3 0 System.out.print(" " + loop) System.out.print System.out System System.out " " + loop " " loop {
                    for(int x = loop; x > 0; x/=10){
                        if(x % 10 == 3) {
                            System.out.print(" " + loop);
                            break;
                        }
                    }
                } for(int x = loop; x > 0; x/=10){
                        if(x % 10 == 3) {
                            System.out.print(" " + loop);
                            break;
                        }
                    } int x = loop; int x = loop; x loop x > 0 x 0 x/=10 x/=10 x 10 {
                        if(x % 10 == 3) {
                            System.out.print(" " + loop);
                            break;
                        }
                    } {
                        if(x % 10 == 3) {
                            System.out.print(" " + loop);
                            break;
                        }
                    } if(x % 10 == 3) {
                            System.out.print(" " + loop);
                            break;
                        } x % 10 == 3 x % 10 x 10 3 {
                            System.out.print(" " + loop);
                            break;
                        } System.out.print(" " + loop) System.out.print System.out System System.out " " + loop " " loop break; System.out.println() System.out.println System.out System System.out String[] args args public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();
        int a = Integer.parseInt(str);

        if(a >= 3){
            for(int loop = 1; loop <= a; loop++){
                if(loop % 3 == 0) System.out.print(" " + loop);
                else {
                    for(int x = loop; x > 0; x/=10){
                        if(x % 10 == 3) {
                            System.out.print(" " + loop);
                            break;
                        }
                    }
                }
            }
        }
        System.out.println();
    }
} public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();
        int a = Integer.parseInt(str);

        if(a >= 3){
            for(int loop = 1; loop <= a; loop++){
                if(loop % 3 == 0) System.out.print(" " + loop);
                else {
                    for(int x = loop; x > 0; x/=10){
                        if(x % 10 == 3) {
                            System.out.print(" " + loop);
                            break;
                        }
                    }
                }
            }
        }
        System.out.println();
    }
} Main
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();
        int a = Integer.parseInt(str);

        if(a >= 3){
            for(int loop = 1; loop <= a; loop++){
                if(loop % 3 == 0) System.out.print(" " + loop);
                else {
                    for(int x = loop; x > 0; x/=10){
                        if(x % 10 == 3) {
                            System.out.print(" " + loop);
                            break;
                        }
                    }
                }
            }
        }
        System.out.println();
    }
}