import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{
	public static void main(String[] args)throws IOException{
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader reader = new BufferedReader(isr);
		
		int n = Integer.parseInt(reader.readLine());
		
		for(int i = 1; i <= n; i++){
			if(String.valueOf(i).indexOf("3") != -1 ||
			   i % 3 == 0){
				System.out.print(" " + i);
			}
		}
		System.out.println();
		
		reader.close();
	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main{
	public static void main(String[] args)throws IOException{
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader reader = new BufferedReader(isr);
		
		int n = Integer.parseInt(reader.readLine());
		
		for(int i = 1; i <= n; i++){
			if(String.valueOf(i).indexOf("3") != -1 ||
			   i % 3 == 0){
				System.out.print(" " + i);
			}
		}
		System.out.println();
		
		reader.close();
	}
} Main public static void main(String[] args)throws IOException{
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader reader = new BufferedReader(isr);
		
		int n = Integer.parseInt(reader.readLine());
		
		for(int i = 1; i <= n; i++){
			if(String.valueOf(i).indexOf("3") != -1 ||
			   i % 3 == 0){
				System.out.print(" " + i);
			}
		}
		System.out.println();
		
		reader.close();
	} main {
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader reader = new BufferedReader(isr);
		
		int n = Integer.parseInt(reader.readLine());
		
		for(int i = 1; i <= n; i++){
			if(String.valueOf(i).indexOf("3") != -1 ||
			   i % 3 == 0){
				System.out.print(" " + i);
			}
		}
		System.out.println();
		
		reader.close();
	} InputStreamReader isr = new InputStreamReader(System.in); isr new InputStreamReader(System.in) BufferedReader reader = new BufferedReader(isr); reader new BufferedReader(isr) int n = Integer.parseInt(reader.readLine()); n Integer.parseInt(reader.readLine()) Integer.parseInt Integer reader.readLine() reader.readLine reader for(int i = 1; i <= n; i++){
			if(String.valueOf(i).indexOf("3") != -1 ||
			   i % 3 == 0){
				System.out.print(" " + i);
			}
		} int i = 1; int i = 1; i 1 i <= n i n i++ i++ i {
			if(String.valueOf(i).indexOf("3") != -1 ||
			   i % 3 == 0){
				System.out.print(" " + i);
			}
		} {
			if(String.valueOf(i).indexOf("3") != -1 ||
			   i % 3 == 0){
				System.out.print(" " + i);
			}
		} if(String.valueOf(i).indexOf("3") != -1 ||
			   i % 3 == 0){
				System.out.print(" " + i);
			} String.valueOf(i).indexOf("3") != -1 ||
			   i % 3 == 0 String.valueOf(i).indexOf("3") != -1 String.valueOf(i).indexOf("3") String.valueOf(i).indexOf String.valueOf(i) String.valueOf String i "3" -1 1 i % 3 == 0 i % 3 i 3 0 {
				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 reader.close() reader.close reader String[] args args public class Main{
	public static void main(String[] args)throws IOException{
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader reader = new BufferedReader(isr);
		
		int n = Integer.parseInt(reader.readLine());
		
		for(int i = 1; i <= n; i++){
			if(String.valueOf(i).indexOf("3") != -1 ||
			   i % 3 == 0){
				System.out.print(" " + i);
			}
		}
		System.out.println();
		
		reader.close();
	}
} public class Main{
	public static void main(String[] args)throws IOException{
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader reader = new BufferedReader(isr);
		
		int n = Integer.parseInt(reader.readLine());
		
		for(int i = 1; i <= n; i++){
			if(String.valueOf(i).indexOf("3") != -1 ||
			   i % 3 == 0){
				System.out.print(" " + i);
			}
		}
		System.out.println();
		
		reader.close();
	}
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{
	public static void main(String[] args)throws IOException{
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader reader = new BufferedReader(isr);
		
		int n = Integer.parseInt(reader.readLine());
		
		for(int i = 1; i <= n; i++){
			if(String.valueOf(i).indexOf("3") != -1 ||
			   i % 3 == 0){
				System.out.print(" " + i);
			}
		}
		System.out.println();
		
		reader.close();
	}
}