import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws java.lang.Exception
	{
		Scanner scan = new Scanner(System.in);
		int n;
		n = scan.nextInt();
		
		for(int j = 1; j < n + 1; j++) {
			if(j % 3 == 0||Integer.toString(j).contains("3")) {
				System.out.print(" " + j);
			}
		}
		
		System.out.println();
	}

} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) throws java.lang.Exception
	{
		Scanner scan = new Scanner(System.in);
		int n;
		n = scan.nextInt();
		
		for(int j = 1; j < n + 1; j++) {
			if(j % 3 == 0||Integer.toString(j).contains("3")) {
				System.out.print(" " + j);
			}
		}
		
		System.out.println();
	}

} Main public static void main(String[] args) throws java.lang.Exception
	{
		Scanner scan = new Scanner(System.in);
		int n;
		n = scan.nextInt();
		
		for(int j = 1; j < n + 1; j++) {
			if(j % 3 == 0||Integer.toString(j).contains("3")) {
				System.out.print(" " + j);
			}
		}
		
		System.out.println();
	} main {
		Scanner scan = new Scanner(System.in);
		int n;
		n = scan.nextInt();
		
		for(int j = 1; j < n + 1; j++) {
			if(j % 3 == 0||Integer.toString(j).contains("3")) {
				System.out.print(" " + j);
			}
		}
		
		System.out.println();
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int n; n n = scan.nextInt() n scan.nextInt() scan.nextInt scan for(int j = 1; j < n + 1; j++) {
			if(j % 3 == 0||Integer.toString(j).contains("3")) {
				System.out.print(" " + j);
			}
		} int j = 1; int j = 1; j 1 j < n + 1 j n + 1 n 1 j++ j++ j {
			if(j % 3 == 0||Integer.toString(j).contains("3")) {
				System.out.print(" " + j);
			}
		} {
			if(j % 3 == 0||Integer.toString(j).contains("3")) {
				System.out.print(" " + j);
			}
		} if(j % 3 == 0||Integer.toString(j).contains("3")) {
				System.out.print(" " + j);
			} j % 3 == 0||Integer.toString(j).contains("3") j % 3 == 0 j % 3 j 3 0 Integer.toString(j).contains("3") Integer.toString(j).contains Integer.toString(j) Integer.toString Integer j "3" {
				System.out.print(" " + j);
			} System.out.print(" " + j) System.out.print System.out System System.out " " + j " " j System.out.println() System.out.println System.out System System.out String[] args args public class Main {

	public static void main(String[] args) throws java.lang.Exception
	{
		Scanner scan = new Scanner(System.in);
		int n;
		n = scan.nextInt();
		
		for(int j = 1; j < n + 1; j++) {
			if(j % 3 == 0||Integer.toString(j).contains("3")) {
				System.out.print(" " + j);
			}
		}
		
		System.out.println();
	}

} public class Main {

	public static void main(String[] args) throws java.lang.Exception
	{
		Scanner scan = new Scanner(System.in);
		int n;
		n = scan.nextInt();
		
		for(int j = 1; j < n + 1; j++) {
			if(j % 3 == 0||Integer.toString(j).contains("3")) {
				System.out.print(" " + j);
			}
		}
		
		System.out.println();
	}

} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws java.lang.Exception
	{
		Scanner scan = new Scanner(System.in);
		int n;
		n = scan.nextInt();
		
		for(int j = 1; j < n + 1; j++) {
			if(j % 3 == 0||Integer.toString(j).contains("3")) {
				System.out.print(" " + j);
			}
		}
		
		System.out.println();
	}

}