import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int i;
        for(int x = 1; x <= n; x++){
            if(String.valueOf(x).contains("3")){
                System.out.print(" " + x);
            }
            else if(x % 3 == 0){
                System.out.print(" " + x);
            }
            else if(x % 10 == 3){
                System.out.print(" " + x);
            }
            else{
                i = x /10;
                if(i % 10 == 3){
                    System.out.print(" " + x);
                }
            }
        }
        System.out.println();
    }
} import java.util.Scanner; Scanner java.util public class Main{
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int i;
        for(int x = 1; x <= n; x++){
            if(String.valueOf(x).contains("3")){
                System.out.print(" " + x);
            }
            else if(x % 3 == 0){
                System.out.print(" " + x);
            }
            else if(x % 10 == 3){
                System.out.print(" " + x);
            }
            else{
                i = x /10;
                if(i % 10 == 3){
                    System.out.print(" " + x);
                }
            }
        }
        System.out.println();
    }
} Main public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int i;
        for(int x = 1; x <= n; x++){
            if(String.valueOf(x).contains("3")){
                System.out.print(" " + x);
            }
            else if(x % 3 == 0){
                System.out.print(" " + x);
            }
            else if(x % 10 == 3){
                System.out.print(" " + x);
            }
            else{
                i = x /10;
                if(i % 10 == 3){
                    System.out.print(" " + x);
                }
            }
        }
        System.out.println();
    } main {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int i;
        for(int x = 1; x <= n; x++){
            if(String.valueOf(x).contains("3")){
                System.out.print(" " + x);
            }
            else if(x % 3 == 0){
                System.out.print(" " + x);
            }
            else if(x % 10 == 3){
                System.out.print(" " + x);
            }
            else{
                i = x /10;
                if(i % 10 == 3){
                    System.out.print(" " + x);
                }
            }
        }
        System.out.println();
    } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan int i; i for(int x = 1; x <= n; x++){
            if(String.valueOf(x).contains("3")){
                System.out.print(" " + x);
            }
            else if(x % 3 == 0){
                System.out.print(" " + x);
            }
            else if(x % 10 == 3){
                System.out.print(" " + x);
            }
            else{
                i = x /10;
                if(i % 10 == 3){
                    System.out.print(" " + x);
                }
            }
        } int x = 1; int x = 1; x 1 x <= n x n x++ x++ x {
            if(String.valueOf(x).contains("3")){
                System.out.print(" " + x);
            }
            else if(x % 3 == 0){
                System.out.print(" " + x);
            }
            else if(x % 10 == 3){
                System.out.print(" " + x);
            }
            else{
                i = x /10;
                if(i % 10 == 3){
                    System.out.print(" " + x);
                }
            }
        } {
            if(String.valueOf(x).contains("3")){
                System.out.print(" " + x);
            }
            else if(x % 3 == 0){
                System.out.print(" " + x);
            }
            else if(x % 10 == 3){
                System.out.print(" " + x);
            }
            else{
                i = x /10;
                if(i % 10 == 3){
                    System.out.print(" " + x);
                }
            }
        } if(String.valueOf(x).contains("3")){
                System.out.print(" " + x);
            }
            else if(x % 3 == 0){
                System.out.print(" " + x);
            }
            else if(x % 10 == 3){
                System.out.print(" " + x);
            }
            else{
                i = x /10;
                if(i % 10 == 3){
                    System.out.print(" " + x);
                }
            } String.valueOf(x).contains("3") String.valueOf(x).contains String.valueOf(x) String.valueOf String x "3" {
                System.out.print(" " + x);
            } System.out.print(" " + x) System.out.print System.out System System.out " " + x " " x if(x % 3 == 0){
                System.out.print(" " + x);
            }
            else if(x % 10 == 3){
                System.out.print(" " + x);
            }
            else{
                i = x /10;
                if(i % 10 == 3){
                    System.out.print(" " + x);
                }
            } x % 3 == 0 x % 3 x 3 0 {
                System.out.print(" " + x);
            } System.out.print(" " + x) System.out.print System.out System System.out " " + x " " x if(x % 10 == 3){
                System.out.print(" " + x);
            }
            else{
                i = x /10;
                if(i % 10 == 3){
                    System.out.print(" " + x);
                }
            } x % 10 == 3 x % 10 x 10 3 {
                System.out.print(" " + x);
            } System.out.print(" " + x) System.out.print System.out System System.out " " + x " " x {
                i = x /10;
                if(i % 10 == 3){
                    System.out.print(" " + x);
                }
            } i = x /10 i x /10 x 10 if(i % 10 == 3){
                    System.out.print(" " + x);
                } i % 10 == 3 i % 10 i 10 3 {
                    System.out.print(" " + x);
                } System.out.print(" " + x) System.out.print System.out System System.out " " + x " " x System.out.println() System.out.println System.out System System.out String[] args args public class Main{
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int i;
        for(int x = 1; x <= n; x++){
            if(String.valueOf(x).contains("3")){
                System.out.print(" " + x);
            }
            else if(x % 3 == 0){
                System.out.print(" " + x);
            }
            else if(x % 10 == 3){
                System.out.print(" " + x);
            }
            else{
                i = x /10;
                if(i % 10 == 3){
                    System.out.print(" " + x);
                }
            }
        }
        System.out.println();
    }
} public class Main{
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int i;
        for(int x = 1; x <= n; x++){
            if(String.valueOf(x).contains("3")){
                System.out.print(" " + x);
            }
            else if(x % 3 == 0){
                System.out.print(" " + x);
            }
            else if(x % 10 == 3){
                System.out.print(" " + x);
            }
            else{
                i = x /10;
                if(i % 10 == 3){
                    System.out.print(" " + x);
                }
            }
        }
        System.out.println();
    }
} Main
import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int i;
        for(int x = 1; x <= n; x++){
            if(String.valueOf(x).contains("3")){
                System.out.print(" " + x);
            }
            else if(x % 3 == 0){
                System.out.print(" " + x);
            }
            else if(x % 10 == 3){
                System.out.print(" " + x);
            }
            else{
                i = x /10;
                if(i % 10 == 3){
                    System.out.print(" " + x);
                }
            }
        }
        System.out.println();
    }
}
