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

public class Main {

	public static void main(String[] args) throws NumberFormatException,
			IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		long n = Long.parseLong(br.readLine());
		call(n);
	}

	private static void call(long n) {
		StringBuilder sb = new StringBuilder();
		for(long i = 1;i <= n;i++){
			if(i % 3 == 0 || String.valueOf(i).indexOf("3") != -1){
				sb.append(String.format(" %d", i));
			}
		}
		System.out.println(sb.toString());
	}

} 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 NumberFormatException,
			IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		long n = Long.parseLong(br.readLine());
		call(n);
	}

	private static void call(long n) {
		StringBuilder sb = new StringBuilder();
		for(long i = 1;i <= n;i++){
			if(i % 3 == 0 || String.valueOf(i).indexOf("3") != -1){
				sb.append(String.format(" %d", i));
			}
		}
		System.out.println(sb.toString());
	}

} Main public static void main(String[] args) throws NumberFormatException,
			IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		long n = Long.parseLong(br.readLine());
		call(n);
	} main {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		long n = Long.parseLong(br.readLine());
		call(n);
	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) long n = Long.parseLong(br.readLine()); n Long.parseLong(br.readLine()) Long.parseLong Long br.readLine() br.readLine br call(n) call n String[] args args private static void call(long n) {
		StringBuilder sb = new StringBuilder();
		for(long i = 1;i <= n;i++){
			if(i % 3 == 0 || String.valueOf(i).indexOf("3") != -1){
				sb.append(String.format(" %d", i));
			}
		}
		System.out.println(sb.toString());
	} call {
		StringBuilder sb = new StringBuilder();
		for(long i = 1;i <= n;i++){
			if(i % 3 == 0 || String.valueOf(i).indexOf("3") != -1){
				sb.append(String.format(" %d", i));
			}
		}
		System.out.println(sb.toString());
	} StringBuilder sb = new StringBuilder(); sb new StringBuilder() for(long i = 1;i <= n;i++){
			if(i % 3 == 0 || String.valueOf(i).indexOf("3") != -1){
				sb.append(String.format(" %d", i));
			}
		} long i = 1; long i = 1; i 1 i <= n i n i++ i++ i {
			if(i % 3 == 0 || String.valueOf(i).indexOf("3") != -1){
				sb.append(String.format(" %d", i));
			}
		} {
			if(i % 3 == 0 || String.valueOf(i).indexOf("3") != -1){
				sb.append(String.format(" %d", i));
			}
		} if(i % 3 == 0 || String.valueOf(i).indexOf("3") != -1){
				sb.append(String.format(" %d", i));
			} i % 3 == 0 || String.valueOf(i).indexOf("3") != -1 i % 3 == 0 i % 3 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 {
				sb.append(String.format(" %d", i));
			} sb.append(String.format(" %d", i)) sb.append sb String.format(" %d", i) String.format String " %d" i System.out.println(sb.toString()) System.out.println System.out System System.out sb.toString() sb.toString sb long n n public class Main {

	public static void main(String[] args) throws NumberFormatException,
			IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		long n = Long.parseLong(br.readLine());
		call(n);
	}

	private static void call(long n) {
		StringBuilder sb = new StringBuilder();
		for(long i = 1;i <= n;i++){
			if(i % 3 == 0 || String.valueOf(i).indexOf("3") != -1){
				sb.append(String.format(" %d", i));
			}
		}
		System.out.println(sb.toString());
	}

} public class Main {

	public static void main(String[] args) throws NumberFormatException,
			IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		long n = Long.parseLong(br.readLine());
		call(n);
	}

	private static void call(long n) {
		StringBuilder sb = new StringBuilder();
		for(long i = 1;i <= n;i++){
			if(i % 3 == 0 || String.valueOf(i).indexOf("3") != -1){
				sb.append(String.format(" %d", i));
			}
		}
		System.out.println(sb.toString());
	}

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

public class Main {

	public static void main(String[] args) throws NumberFormatException,
			IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		long n = Long.parseLong(br.readLine());
		call(n);
	}

	private static void call(long n) {
		StringBuilder sb = new StringBuilder();
		for(long i = 1;i <= n;i++){
			if(i % 3 == 0 || String.valueOf(i).indexOf("3") != -1){
				sb.append(String.format(" %d", i));
			}
		}
		System.out.println(sb.toString());
	}

}