public class Main {


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


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


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


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


		public static void main(String[] args) {
		java.util.Scanner scan = new java.util.Scanner(System.in);
		int n = scan.nextInt(); 
		int i;
	
		if(3 <= n && n <= 10000){
			for(i = 1; i <= n; i++){
				if(i % 3 == 0 || i % 10 == 3 || i/10 % 10 == 3 || i/100 % 10 == 3 || i/1000 % 10 == 3){
					
				System.out.print(" "+ i);
				}
				}
	
		}
		System.out.println();
		
		}
			
			
		}