import java.util.*;

public class Main{
	private static final Scanner scan = new Scanner(System.in);

	public static void main(String[] args){
		int n = scan.nextInt();
		for(int i = 1; i <= n; i++){
			String si = String.valueOf(i);
			if(i % 3 == 0){
				System.out.printf(" %s", si);
			} else if(si.contains("3")){
				System.out.printf(" %s", si);
			}
		}
		System.out.printf("\n");
	}
} import java.util.*; util.* java public class Main{
	private static final Scanner scan = new Scanner(System.in);

	public static void main(String[] args){
		int n = scan.nextInt();
		for(int i = 1; i <= n; i++){
			String si = String.valueOf(i);
			if(i % 3 == 0){
				System.out.printf(" %s", si);
			} else if(si.contains("3")){
				System.out.printf(" %s", si);
			}
		}
		System.out.printf("\n");
	}
} Main private static final Scanner scan = new Scanner(System.in); scan new Scanner(System.in) public static void main(String[] args){
		int n = scan.nextInt();
		for(int i = 1; i <= n; i++){
			String si = String.valueOf(i);
			if(i % 3 == 0){
				System.out.printf(" %s", si);
			} else if(si.contains("3")){
				System.out.printf(" %s", si);
			}
		}
		System.out.printf("\n");
	} main {
		int n = scan.nextInt();
		for(int i = 1; i <= n; i++){
			String si = String.valueOf(i);
			if(i % 3 == 0){
				System.out.printf(" %s", si);
			} else if(si.contains("3")){
				System.out.printf(" %s", si);
			}
		}
		System.out.printf("\n");
	} int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan for(int i = 1; i <= n; i++){
			String si = String.valueOf(i);
			if(i % 3 == 0){
				System.out.printf(" %s", si);
			} else if(si.contains("3")){
				System.out.printf(" %s", si);
			}
		} int i = 1; int i = 1; i 1 i <= n i n i++ i++ i {
			String si = String.valueOf(i);
			if(i % 3 == 0){
				System.out.printf(" %s", si);
			} else if(si.contains("3")){
				System.out.printf(" %s", si);
			}
		} {
			String si = String.valueOf(i);
			if(i % 3 == 0){
				System.out.printf(" %s", si);
			} else if(si.contains("3")){
				System.out.printf(" %s", si);
			}
		} String si = String.valueOf(i); si String.valueOf(i) String.valueOf String i if(i % 3 == 0){
				System.out.printf(" %s", si);
			} else if(si.contains("3")){
				System.out.printf(" %s", si);
			} i % 3 == 0 i % 3 i 3 0 {
				System.out.printf(" %s", si);
			} System.out.printf(" %s", si) System.out.printf System.out System System.out " %s" si if(si.contains("3")){
				System.out.printf(" %s", si);
			} si.contains("3") si.contains si "3" {
				System.out.printf(" %s", si);
			} System.out.printf(" %s", si) System.out.printf System.out System System.out " %s" si System.out.printf("\n") System.out.printf System.out System System.out "\n" String[] args args public class Main{
	private static final Scanner scan = new Scanner(System.in);

	public static void main(String[] args){
		int n = scan.nextInt();
		for(int i = 1; i <= n; i++){
			String si = String.valueOf(i);
			if(i % 3 == 0){
				System.out.printf(" %s", si);
			} else if(si.contains("3")){
				System.out.printf(" %s", si);
			}
		}
		System.out.printf("\n");
	}
} public class Main{
	private static final Scanner scan = new Scanner(System.in);

	public static void main(String[] args){
		int n = scan.nextInt();
		for(int i = 1; i <= n; i++){
			String si = String.valueOf(i);
			if(i % 3 == 0){
				System.out.printf(" %s", si);
			} else if(si.contains("3")){
				System.out.printf(" %s", si);
			}
		}
		System.out.printf("\n");
	}
} Main
import java.util.*;

public class Main{
	private static final Scanner scan = new Scanner(System.in);

	public static void main(String[] args){
		int n = scan.nextInt();
		for(int i = 1; i <= n; i++){
			String si = String.valueOf(i);
			if(i % 3 == 0){
				System.out.printf(" %s", si);
			} else if(si.contains("3")){
				System.out.printf(" %s", si);
			}
		}
		System.out.printf("\n");
	}
}