import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner std = new Scanner(System.in);
		int n = Integer.parseInt(std.next());
		String ret = "";
		for (int i=3; i<=n; i++){
			int j = i;
			if(i%3==0){
				ret += " " + i;
			}else{
			while(j>0){
				if(j%10==3){
					ret += " " + i;
					break;
				}else{
					j /= 10;
				}
			}}
		}
		System.out.println(ret);
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args){
		Scanner std = new Scanner(System.in);
		int n = Integer.parseInt(std.next());
		String ret = "";
		for (int i=3; i<=n; i++){
			int j = i;
			if(i%3==0){
				ret += " " + i;
			}else{
			while(j>0){
				if(j%10==3){
					ret += " " + i;
					break;
				}else{
					j /= 10;
				}
			}}
		}
		System.out.println(ret);
	}
} Main public static void main(String[] args){
		Scanner std = new Scanner(System.in);
		int n = Integer.parseInt(std.next());
		String ret = "";
		for (int i=3; i<=n; i++){
			int j = i;
			if(i%3==0){
				ret += " " + i;
			}else{
			while(j>0){
				if(j%10==3){
					ret += " " + i;
					break;
				}else{
					j /= 10;
				}
			}}
		}
		System.out.println(ret);
	} main {
		Scanner std = new Scanner(System.in);
		int n = Integer.parseInt(std.next());
		String ret = "";
		for (int i=3; i<=n; i++){
			int j = i;
			if(i%3==0){
				ret += " " + i;
			}else{
			while(j>0){
				if(j%10==3){
					ret += " " + i;
					break;
				}else{
					j /= 10;
				}
			}}
		}
		System.out.println(ret);
	} Scanner std = new Scanner(System.in); std new Scanner(System.in) int n = Integer.parseInt(std.next()); n Integer.parseInt(std.next()) Integer.parseInt Integer std.next() std.next std String ret = ""; ret "" for (int i=3; i<=n; i++){
			int j = i;
			if(i%3==0){
				ret += " " + i;
			}else{
			while(j>0){
				if(j%10==3){
					ret += " " + i;
					break;
				}else{
					j /= 10;
				}
			}}
		} int i=3; int i=3; i 3 i<=n i n i++ i++ i {
			int j = i;
			if(i%3==0){
				ret += " " + i;
			}else{
			while(j>0){
				if(j%10==3){
					ret += " " + i;
					break;
				}else{
					j /= 10;
				}
			}}
		} {
			int j = i;
			if(i%3==0){
				ret += " " + i;
			}else{
			while(j>0){
				if(j%10==3){
					ret += " " + i;
					break;
				}else{
					j /= 10;
				}
			}}
		} int j = i; j i if(i%3==0){
				ret += " " + i;
			}else{
			while(j>0){
				if(j%10==3){
					ret += " " + i;
					break;
				}else{
					j /= 10;
				}
			}} i%3==0 i%3 i 3 0 {
				ret += " " + i;
			} ret += " " + i ret " " + i " " i {
			while(j>0){
				if(j%10==3){
					ret += " " + i;
					break;
				}else{
					j /= 10;
				}
			}} while(j>0){
				if(j%10==3){
					ret += " " + i;
					break;
				}else{
					j /= 10;
				}
			} j>0 j 0 {
				if(j%10==3){
					ret += " " + i;
					break;
				}else{
					j /= 10;
				}
			} if(j%10==3){
					ret += " " + i;
					break;
				}else{
					j /= 10;
				} j%10==3 j%10 j 10 3 {
					ret += " " + i;
					break;
				} ret += " " + i ret " " + i " " i break; {
					j /= 10;
				} j /= 10 j 10 System.out.println(ret) System.out.println System.out System System.out ret String[] args args public class Main {
	public static void main(String[] args){
		Scanner std = new Scanner(System.in);
		int n = Integer.parseInt(std.next());
		String ret = "";
		for (int i=3; i<=n; i++){
			int j = i;
			if(i%3==0){
				ret += " " + i;
			}else{
			while(j>0){
				if(j%10==3){
					ret += " " + i;
					break;
				}else{
					j /= 10;
				}
			}}
		}
		System.out.println(ret);
	}
} public class Main {
	public static void main(String[] args){
		Scanner std = new Scanner(System.in);
		int n = Integer.parseInt(std.next());
		String ret = "";
		for (int i=3; i<=n; i++){
			int j = i;
			if(i%3==0){
				ret += " " + i;
			}else{
			while(j>0){
				if(j%10==3){
					ret += " " + i;
					break;
				}else{
					j /= 10;
				}
			}}
		}
		System.out.println(ret);
	}
} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner std = new Scanner(System.in);
		int n = Integer.parseInt(std.next());
		String ret = "";
		for (int i=3; i<=n; i++){
			int j = i;
			if(i%3==0){
				ret += " " + i;
			}else{
			while(j>0){
				if(j%10==3){
					ret += " " + i;
					break;
				}else{
					j /= 10;
				}
			}}
		}
		System.out.println(ret);
	}
}