import java.util.Scanner;

public class Main{


    public static void main(String[] args){
    	Scanner scan = new Scanner(System.in);
    	
    	int end_val = scan.nextInt();//end

		for(int cnt = 1; cnt <= end_val; cnt++){//1~end?????§?????°?????????3???????????°?????¨3????????°?????¢???
			if(cnt % 3 == 0){//3???????????°?????§?????????
				System.out.print(" " + cnt);
			}else{
				for(int i = cnt; i > 0;){//i????¨??????¨
					if(i % 10 == 3){//3???????????°?????§?????????????????§??????
							System.out.print(" " + cnt);
							break;
					 }
					 i /= 10;//??????1????????????
				}
			}
		}
		System.out.println();
	    scan.close();
    }
} import java.util.Scanner; Scanner java.util public class Main{


    public static void main(String[] args){
    	Scanner scan = new Scanner(System.in);
    	
    	int end_val = scan.nextInt();//end

		for(int cnt = 1; cnt <= end_val; cnt++){//1~end?????§?????°?????????3???????????°?????¨3????????°?????¢???
			if(cnt % 3 == 0){//3???????????°?????§?????????
				System.out.print(" " + cnt);
			}else{
				for(int i = cnt; i > 0;){//i????¨??????¨
					if(i % 10 == 3){//3???????????°?????§?????????????????§??????
							System.out.print(" " + cnt);
							break;
					 }
					 i /= 10;//??????1????????????
				}
			}
		}
		System.out.println();
	    scan.close();
    }
} Main public static void main(String[] args){
    	Scanner scan = new Scanner(System.in);
    	
    	int end_val = scan.nextInt();//end

		for(int cnt = 1; cnt <= end_val; cnt++){//1~end?????§?????°?????????3???????????°?????¨3????????°?????¢???
			if(cnt % 3 == 0){//3???????????°?????§?????????
				System.out.print(" " + cnt);
			}else{
				for(int i = cnt; i > 0;){//i????¨??????¨
					if(i % 10 == 3){//3???????????°?????§?????????????????§??????
							System.out.print(" " + cnt);
							break;
					 }
					 i /= 10;//??????1????????????
				}
			}
		}
		System.out.println();
	    scan.close();
    } main {
    	Scanner scan = new Scanner(System.in);
    	
    	int end_val = scan.nextInt();//end

		for(int cnt = 1; cnt <= end_val; cnt++){//1~end?????§?????°?????????3???????????°?????¨3????????°?????¢???
			if(cnt % 3 == 0){//3???????????°?????§?????????
				System.out.print(" " + cnt);
			}else{
				for(int i = cnt; i > 0;){//i????¨??????¨
					if(i % 10 == 3){//3???????????°?????§?????????????????§??????
							System.out.print(" " + cnt);
							break;
					 }
					 i /= 10;//??????1????????????
				}
			}
		}
		System.out.println();
	    scan.close();
    } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int end_val = scan.nextInt(); end_val scan.nextInt() scan.nextInt scan for(int cnt = 1; cnt <= end_val; cnt++){//1~end?????§?????°?????????3???????????°?????¨3????????°?????¢???
			if(cnt % 3 == 0){//3???????????°?????§?????????
				System.out.print(" " + cnt);
			}else{
				for(int i = cnt; i > 0;){//i????¨??????¨
					if(i % 10 == 3){//3???????????°?????§?????????????????§??????
							System.out.print(" " + cnt);
							break;
					 }
					 i /= 10;//??????1????????????
				}
			}
		} int cnt = 1; int cnt = 1; cnt 1 cnt <= end_val cnt end_val cnt++ cnt++ cnt {//1~end?????§?????°?????????3???????????°?????¨3????????°?????¢???
			if(cnt % 3 == 0){//3???????????°?????§?????????
				System.out.print(" " + cnt);
			}else{
				for(int i = cnt; i > 0;){//i????¨??????¨
					if(i % 10 == 3){//3???????????°?????§?????????????????§??????
							System.out.print(" " + cnt);
							break;
					 }
					 i /= 10;//??????1????????????
				}
			}
		} {//1~end?????§?????°?????????3???????????°?????¨3????????°?????¢???
			if(cnt % 3 == 0){//3???????????°?????§?????????
				System.out.print(" " + cnt);
			}else{
				for(int i = cnt; i > 0;){//i????¨??????¨
					if(i % 10 == 3){//3???????????°?????§?????????????????§??????
							System.out.print(" " + cnt);
							break;
					 }
					 i /= 10;//??????1????????????
				}
			}
		} if(cnt % 3 == 0){//3???????????°?????§?????????
				System.out.print(" " + cnt);
			}else{
				for(int i = cnt; i > 0;){//i????¨??????¨
					if(i % 10 == 3){//3???????????°?????§?????????????????§??????
							System.out.print(" " + cnt);
							break;
					 }
					 i /= 10;//??????1????????????
				}
			} cnt % 3 == 0 cnt % 3 cnt 3 0 {//3???????????°?????§?????????
				System.out.print(" " + cnt);
			} System.out.print(" " + cnt) System.out.print System.out System System.out " " + cnt " " cnt {
				for(int i = cnt; i > 0;){//i????¨??????¨
					if(i % 10 == 3){//3???????????°?????§?????????????????§??????
							System.out.print(" " + cnt);
							break;
					 }
					 i /= 10;//??????1????????????
				}
			} for(int i = cnt; i > 0;){//i????¨??????¨
					if(i % 10 == 3){//3???????????°?????§?????????????????§??????
							System.out.print(" " + cnt);
							break;
					 }
					 i /= 10;//??????1????????????
				} int i = cnt; int i = cnt; i cnt i > 0 i 0 {//i????¨??????¨
					if(i % 10 == 3){//3???????????°?????§?????????????????§??????
							System.out.print(" " + cnt);
							break;
					 }
					 i /= 10;//??????1????????????
				} {//i????¨??????¨
					if(i % 10 == 3){//3???????????°?????§?????????????????§??????
							System.out.print(" " + cnt);
							break;
					 }
					 i /= 10;//??????1????????????
				} if(i % 10 == 3){//3???????????°?????§?????????????????§??????
							System.out.print(" " + cnt);
							break;
					 } i % 10 == 3 i % 10 i 10 3 {//3???????????°?????§?????????????????§??????
							System.out.print(" " + cnt);
							break;
					 } System.out.print(" " + cnt) System.out.print System.out System System.out " " + cnt " " cnt break; i /= 10 i 10 System.out.println() System.out.println System.out System System.out scan.close() scan.close scan String[] args args public class Main{


    public static void main(String[] args){
    	Scanner scan = new Scanner(System.in);
    	
    	int end_val = scan.nextInt();//end

		for(int cnt = 1; cnt <= end_val; cnt++){//1~end?????§?????°?????????3???????????°?????¨3????????°?????¢???
			if(cnt % 3 == 0){//3???????????°?????§?????????
				System.out.print(" " + cnt);
			}else{
				for(int i = cnt; i > 0;){//i????¨??????¨
					if(i % 10 == 3){//3???????????°?????§?????????????????§??????
							System.out.print(" " + cnt);
							break;
					 }
					 i /= 10;//??????1????????????
				}
			}
		}
		System.out.println();
	    scan.close();
    }
} public class Main{


    public static void main(String[] args){
    	Scanner scan = new Scanner(System.in);
    	
    	int end_val = scan.nextInt();//end

		for(int cnt = 1; cnt <= end_val; cnt++){//1~end?????§?????°?????????3???????????°?????¨3????????°?????¢???
			if(cnt % 3 == 0){//3???????????°?????§?????????
				System.out.print(" " + cnt);
			}else{
				for(int i = cnt; i > 0;){//i????¨??????¨
					if(i % 10 == 3){//3???????????°?????§?????????????????§??????
							System.out.print(" " + cnt);
							break;
					 }
					 i /= 10;//??????1????????????
				}
			}
		}
		System.out.println();
	    scan.close();
    }
} Main
import java.util.Scanner;

public class Main{


    public static void main(String[] args){
    	Scanner scan = new Scanner(System.in);
    	
    	int end_val = scan.nextInt();//end

		for(int cnt = 1; cnt <= end_val; cnt++){//1~end?????§?????°?????????3???????????°?????¨3????????°?????¢???
			if(cnt % 3 == 0){//3???????????°?????§?????????
				System.out.print(" " + cnt);
			}else{
				for(int i = cnt; i > 0;){//i????¨??????¨
					if(i % 10 == 3){//3???????????°?????§?????????????????§??????
							System.out.print(" " + cnt);
							break;
					 }
					 i /= 10;//??????1????????????
				}
			}
		}
		System.out.println();
	    scan.close();
    }
}