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

public class Main {
	public static void main(String[] args)throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();

		int number = Integer.parseInt(br.readLine());

		for(int i = 1; i <= number; i++){
			String count = String.valueOf(i);
				if(i % 3 == 0 || i % 10 == 3 || count.contains("3")){
					sb.append(" " +i);
				}
			}
		System.out.println(sb);
	}
} 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{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();

		int number = Integer.parseInt(br.readLine());

		for(int i = 1; i <= number; i++){
			String count = String.valueOf(i);
				if(i % 3 == 0 || i % 10 == 3 || count.contains("3")){
					sb.append(" " +i);
				}
			}
		System.out.println(sb);
	}
} Main public static void main(String[] args)throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();

		int number = Integer.parseInt(br.readLine());

		for(int i = 1; i <= number; i++){
			String count = String.valueOf(i);
				if(i % 3 == 0 || i % 10 == 3 || count.contains("3")){
					sb.append(" " +i);
				}
			}
		System.out.println(sb);
	} main {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();

		int number = Integer.parseInt(br.readLine());

		for(int i = 1; i <= number; i++){
			String count = String.valueOf(i);
				if(i % 3 == 0 || i % 10 == 3 || count.contains("3")){
					sb.append(" " +i);
				}
			}
		System.out.println(sb);
	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) StringBuilder sb = new StringBuilder(); sb new StringBuilder() int number = Integer.parseInt(br.readLine()); number Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br for(int i = 1; i <= number; i++){
			String count = String.valueOf(i);
				if(i % 3 == 0 || i % 10 == 3 || count.contains("3")){
					sb.append(" " +i);
				}
			} int i = 1; int i = 1; i 1 i <= number i number i++ i++ i {
			String count = String.valueOf(i);
				if(i % 3 == 0 || i % 10 == 3 || count.contains("3")){
					sb.append(" " +i);
				}
			} {
			String count = String.valueOf(i);
				if(i % 3 == 0 || i % 10 == 3 || count.contains("3")){
					sb.append(" " +i);
				}
			} String count = String.valueOf(i); count String.valueOf(i) String.valueOf String i if(i % 3 == 0 || i % 10 == 3 || count.contains("3")){
					sb.append(" " +i);
				} i % 3 == 0 || i % 10 == 3 || count.contains("3") i % 3 == 0 || i % 10 == 3 || count.contains("3") i % 3 == 0 i % 3 i 3 0 i % 10 == 3 i % 10 i 10 3 count.contains("3") count.contains count "3" {
					sb.append(" " +i);
				} sb.append(" " +i) sb.append sb " " +i " " i System.out.println(sb) System.out.println System.out System System.out sb String[] args args public class Main {
	public static void main(String[] args)throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();

		int number = Integer.parseInt(br.readLine());

		for(int i = 1; i <= number; i++){
			String count = String.valueOf(i);
				if(i % 3 == 0 || i % 10 == 3 || count.contains("3")){
					sb.append(" " +i);
				}
			}
		System.out.println(sb);
	}
} public class Main {
	public static void main(String[] args)throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();

		int number = Integer.parseInt(br.readLine());

		for(int i = 1; i <= number; i++){
			String count = String.valueOf(i);
				if(i % 3 == 0 || i % 10 == 3 || count.contains("3")){
					sb.append(" " +i);
				}
			}
		System.out.println(sb);
	}
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args)throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();

		int number = Integer.parseInt(br.readLine());

		for(int i = 1; i <= number; i++){
			String count = String.valueOf(i);
				if(i % 3 == 0 || i % 10 == 3 || count.contains("3")){
					sb.append(" " +i);
				}
			}
		System.out.println(sb);
	}
}