import java.util.Scanner;

public class Main{
	public static void main(String args[]){

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String nabe = "";

		for(int i = 3; i <= N ; i++){
			if ( i % 3 == 0 || Integer.toString(i).contains("3")) {

				nabe += (" " + i);
			}
		}
		System.out.println(nabe);
	}
} import java.util.Scanner; Scanner java.util public class Main{
	public static void main(String args[]){

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String nabe = "";

		for(int i = 3; i <= N ; i++){
			if ( i % 3 == 0 || Integer.toString(i).contains("3")) {

				nabe += (" " + i);
			}
		}
		System.out.println(nabe);
	}
} Main public static void main(String args[]){

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String nabe = "";

		for(int i = 3; i <= N ; i++){
			if ( i % 3 == 0 || Integer.toString(i).contains("3")) {

				nabe += (" " + i);
			}
		}
		System.out.println(nabe);
	} main {

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String nabe = "";

		for(int i = 3; i <= N ; i++){
			if ( i % 3 == 0 || Integer.toString(i).contains("3")) {

				nabe += (" " + i);
			}
		}
		System.out.println(nabe);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc String nabe = ""; nabe "" for(int i = 3; i <= N ; i++){
			if ( i % 3 == 0 || Integer.toString(i).contains("3")) {

				nabe += (" " + i);
			}
		} int i = 3; int i = 3; i 3 i <= N i N i++ i++ i {
			if ( i % 3 == 0 || Integer.toString(i).contains("3")) {

				nabe += (" " + i);
			}
		} {
			if ( i % 3 == 0 || Integer.toString(i).contains("3")) {

				nabe += (" " + i);
			}
		} if ( i % 3 == 0 || Integer.toString(i).contains("3")) {

				nabe += (" " + i);
			} i % 3 == 0 || Integer.toString(i).contains("3") i % 3 == 0 i % 3 i 3 0 Integer.toString(i).contains("3") Integer.toString(i).contains Integer.toString(i) Integer.toString Integer i "3" {

				nabe += (" " + i);
			} nabe += (" " + i) nabe (" " + i) " " i System.out.println(nabe) System.out.println System.out System System.out nabe String args[] args public class Main{
	public static void main(String args[]){

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String nabe = "";

		for(int i = 3; i <= N ; i++){
			if ( i % 3 == 0 || Integer.toString(i).contains("3")) {

				nabe += (" " + i);
			}
		}
		System.out.println(nabe);
	}
} public class Main{
	public static void main(String args[]){

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String nabe = "";

		for(int i = 3; i <= N ; i++){
			if ( i % 3 == 0 || Integer.toString(i).contains("3")) {

				nabe += (" " + i);
			}
		}
		System.out.println(nabe);
	}
} Main
import java.util.Scanner;

public class Main{
	public static void main(String args[]){

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String nabe = "";

		for(int i = 3; i <= N ; i++){
			if ( i % 3 == 0 || Integer.toString(i).contains("3")) {

				nabe += (" " + i);
			}
		}
		System.out.println(nabe);
	}
}