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) {
		write(n);
		System.out.println();
	}

	private static void write(long n) {
		if (n > 1){
			write(n - 1);
		}
		if(n % 3 == 0 || String.valueOf(n).indexOf("3") != -1){
			System.out.printf(" %d", n);
		}
	}

} 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) {
		write(n);
		System.out.println();
	}

	private static void write(long n) {
		if (n > 1){
			write(n - 1);
		}
		if(n % 3 == 0 || String.valueOf(n).indexOf("3") != -1){
			System.out.printf(" %d", n);
		}
	}

} 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) {
		write(n);
		System.out.println();
	} call {
		write(n);
		System.out.println();
	} write(n) write n System.out.println() System.out.println System.out System System.out long n n private static void write(long n) {
		if (n > 1){
			write(n - 1);
		}
		if(n % 3 == 0 || String.valueOf(n).indexOf("3") != -1){
			System.out.printf(" %d", n);
		}
	} write {
		if (n > 1){
			write(n - 1);
		}
		if(n % 3 == 0 || String.valueOf(n).indexOf("3") != -1){
			System.out.printf(" %d", n);
		}
	} if (n > 1){
			write(n - 1);
		} n > 1 n 1 {
			write(n - 1);
		} write(n - 1) write n - 1 n 1 if(n % 3 == 0 || String.valueOf(n).indexOf("3") != -1){
			System.out.printf(" %d", n);
		} n % 3 == 0 || String.valueOf(n).indexOf("3") != -1 n % 3 == 0 n % 3 n 3 0 String.valueOf(n).indexOf("3") != -1 String.valueOf(n).indexOf("3") String.valueOf(n).indexOf String.valueOf(n) String.valueOf String n "3" -1 1 {
			System.out.printf(" %d", n);
		} System.out.printf(" %d", n) System.out.printf System.out System System.out " %d" n 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) {
		write(n);
		System.out.println();
	}

	private static void write(long n) {
		if (n > 1){
			write(n - 1);
		}
		if(n % 3 == 0 || String.valueOf(n).indexOf("3") != -1){
			System.out.printf(" %d", 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) {
		write(n);
		System.out.println();
	}

	private static void write(long n) {
		if (n > 1){
			write(n - 1);
		}
		if(n % 3 == 0 || String.valueOf(n).indexOf("3") != -1){
			System.out.printf(" %d", n);
		}
	}

} 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) {
		write(n);
		System.out.println();
	}

	private static void write(long n) {
		if (n > 1){
			write(n - 1);
		}
		if(n % 3 == 0 || String.valueOf(n).indexOf("3") != -1){
			System.out.printf(" %d", n);
		}
	}

}