import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		sc.close();
		
		for(Integer i = 1 ; i <= n ; i++){
			//3??§?????????????????´???
			if(i%3==0){
				System.out.print(" " + i.toString());
			}
			else{	//3??§????????????????????´??????3??????????????¢???
				int x = i;
				while(x > 0){
					if(x%10==3){
						System.out.print(" " + i.toString());
						break;
					}
					x = x/10;
				}				
			}
		}
System.out.println();
	}
} import java.util.Scanner; Scanner java.util class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		sc.close();
		
		for(Integer i = 1 ; i <= n ; i++){
			//3??§?????????????????´???
			if(i%3==0){
				System.out.print(" " + i.toString());
			}
			else{	//3??§????????????????????´??????3??????????????¢???
				int x = i;
				while(x > 0){
					if(x%10==3){
						System.out.print(" " + i.toString());
						break;
					}
					x = x/10;
				}				
			}
		}
System.out.println();
	}
} Main public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		sc.close();
		
		for(Integer i = 1 ; i <= n ; i++){
			//3??§?????????????????´???
			if(i%3==0){
				System.out.print(" " + i.toString());
			}
			else{	//3??§????????????????????´??????3??????????????¢???
				int x = i;
				while(x > 0){
					if(x%10==3){
						System.out.print(" " + i.toString());
						break;
					}
					x = x/10;
				}				
			}
		}
System.out.println();
	} main {
		// TODO ?????????????????????????????????????????????
		
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		sc.close();
		
		for(Integer i = 1 ; i <= n ; i++){
			//3??§?????????????????´???
			if(i%3==0){
				System.out.print(" " + i.toString());
			}
			else{	//3??§????????????????????´??????3??????????????¢???
				int x = i;
				while(x > 0){
					if(x%10==3){
						System.out.print(" " + i.toString());
						break;
					}
					x = x/10;
				}				
			}
		}
System.out.println();
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc sc.close() sc.close sc for(Integer i = 1 ; i <= n ; i++){
			//3??§?????????????????´???
			if(i%3==0){
				System.out.print(" " + i.toString());
			}
			else{	//3??§????????????????????´??????3??????????????¢???
				int x = i;
				while(x > 0){
					if(x%10==3){
						System.out.print(" " + i.toString());
						break;
					}
					x = x/10;
				}				
			}
		} Integer i = 1 ; Integer i = 1 ; i 1 i <= n i n i++ i++ i {
			//3??§?????????????????´???
			if(i%3==0){
				System.out.print(" " + i.toString());
			}
			else{	//3??§????????????????????´??????3??????????????¢???
				int x = i;
				while(x > 0){
					if(x%10==3){
						System.out.print(" " + i.toString());
						break;
					}
					x = x/10;
				}				
			}
		} {
			//3??§?????????????????´???
			if(i%3==0){
				System.out.print(" " + i.toString());
			}
			else{	//3??§????????????????????´??????3??????????????¢???
				int x = i;
				while(x > 0){
					if(x%10==3){
						System.out.print(" " + i.toString());
						break;
					}
					x = x/10;
				}				
			}
		} if(i%3==0){
				System.out.print(" " + i.toString());
			}
			else{	//3??§????????????????????´??????3??????????????¢???
				int x = i;
				while(x > 0){
					if(x%10==3){
						System.out.print(" " + i.toString());
						break;
					}
					x = x/10;
				}				
			} i%3==0 i%3 i 3 0 {
				System.out.print(" " + i.toString());
			} System.out.print(" " + i.toString()) System.out.print System.out System System.out " " + i.toString() " " i.toString() i.toString i {	//3??§????????????????????´??????3??????????????¢???
				int x = i;
				while(x > 0){
					if(x%10==3){
						System.out.print(" " + i.toString());
						break;
					}
					x = x/10;
				}				
			} int x = i; x i while(x > 0){
					if(x%10==3){
						System.out.print(" " + i.toString());
						break;
					}
					x = x/10;
				} x > 0 x 0 {
					if(x%10==3){
						System.out.print(" " + i.toString());
						break;
					}
					x = x/10;
				} if(x%10==3){
						System.out.print(" " + i.toString());
						break;
					} x%10==3 x%10 x 10 3 {
						System.out.print(" " + i.toString());
						break;
					} System.out.print(" " + i.toString()) System.out.print System.out System System.out " " + i.toString() " " i.toString() i.toString i break; x = x/10 x x/10 x 10 System.out.println() System.out.println System.out System System.out String[] args args
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		sc.close();
		
		for(Integer i = 1 ; i <= n ; i++){
			//3??§?????????????????´???
			if(i%3==0){
				System.out.print(" " + i.toString());
			}
			else{	//3??§????????????????????´??????3??????????????¢???
				int x = i;
				while(x > 0){
					if(x%10==3){
						System.out.print(" " + i.toString());
						break;
					}
					x = x/10;
				}				
			}
		}
System.out.println();
	}
}