import java.util.Scanner;


public class Main {
	public static void main(String[] args)
	{
		Scanner scanner = new Scanner(System.in);
		
		int n = scanner.nextInt();
		
		for(int i=1; i<=n; i++)
		{
			boolean is = false;
			for(int j=i; j>0; j/=10)
			{
				if(j%10 == 3)
				{
					is = true;
					break;
				}
			}
			if(i%3 == 0)
			{
				is = true;
			}
			
			if(is)
			{
				System.out.print(" ");
				System.out.print(i);
			}
		}
		System.out.println("");
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args)
	{
		Scanner scanner = new Scanner(System.in);
		
		int n = scanner.nextInt();
		
		for(int i=1; i<=n; i++)
		{
			boolean is = false;
			for(int j=i; j>0; j/=10)
			{
				if(j%10 == 3)
				{
					is = true;
					break;
				}
			}
			if(i%3 == 0)
			{
				is = true;
			}
			
			if(is)
			{
				System.out.print(" ");
				System.out.print(i);
			}
		}
		System.out.println("");
	}
} Main public static void main(String[] args)
	{
		Scanner scanner = new Scanner(System.in);
		
		int n = scanner.nextInt();
		
		for(int i=1; i<=n; i++)
		{
			boolean is = false;
			for(int j=i; j>0; j/=10)
			{
				if(j%10 == 3)
				{
					is = true;
					break;
				}
			}
			if(i%3 == 0)
			{
				is = true;
			}
			
			if(is)
			{
				System.out.print(" ");
				System.out.print(i);
			}
		}
		System.out.println("");
	} main {
		Scanner scanner = new Scanner(System.in);
		
		int n = scanner.nextInt();
		
		for(int i=1; i<=n; i++)
		{
			boolean is = false;
			for(int j=i; j>0; j/=10)
			{
				if(j%10 == 3)
				{
					is = true;
					break;
				}
			}
			if(i%3 == 0)
			{
				is = true;
			}
			
			if(is)
			{
				System.out.print(" ");
				System.out.print(i);
			}
		}
		System.out.println("");
	} Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int n = scanner.nextInt(); n scanner.nextInt() scanner.nextInt scanner for(int i=1; i<=n; i++)
		{
			boolean is = false;
			for(int j=i; j>0; j/=10)
			{
				if(j%10 == 3)
				{
					is = true;
					break;
				}
			}
			if(i%3 == 0)
			{
				is = true;
			}
			
			if(is)
			{
				System.out.print(" ");
				System.out.print(i);
			}
		} int i=1; int i=1; i 1 i<=n i n i++ i++ i {
			boolean is = false;
			for(int j=i; j>0; j/=10)
			{
				if(j%10 == 3)
				{
					is = true;
					break;
				}
			}
			if(i%3 == 0)
			{
				is = true;
			}
			
			if(is)
			{
				System.out.print(" ");
				System.out.print(i);
			}
		} {
			boolean is = false;
			for(int j=i; j>0; j/=10)
			{
				if(j%10 == 3)
				{
					is = true;
					break;
				}
			}
			if(i%3 == 0)
			{
				is = true;
			}
			
			if(is)
			{
				System.out.print(" ");
				System.out.print(i);
			}
		} boolean is = false; is false for(int j=i; j>0; j/=10)
			{
				if(j%10 == 3)
				{
					is = true;
					break;
				}
			} int j=i; int j=i; j i j>0 j 0 j/=10 j/=10 j 10 {
				if(j%10 == 3)
				{
					is = true;
					break;
				}
			} {
				if(j%10 == 3)
				{
					is = true;
					break;
				}
			} if(j%10 == 3)
				{
					is = true;
					break;
				} j%10 == 3 j%10 j 10 3 {
					is = true;
					break;
				} is = true is true break; if(i%3 == 0)
			{
				is = true;
			} i%3 == 0 i%3 i 3 0 {
				is = true;
			} is = true is true if(is)
			{
				System.out.print(" ");
				System.out.print(i);
			} is {
				System.out.print(" ");
				System.out.print(i);
			} System.out.print(" ") System.out.print System.out System System.out " " System.out.print(i) System.out.print System.out System System.out i System.out.println("") System.out.println System.out System System.out "" String[] args args public class Main {
	public static void main(String[] args)
	{
		Scanner scanner = new Scanner(System.in);
		
		int n = scanner.nextInt();
		
		for(int i=1; i<=n; i++)
		{
			boolean is = false;
			for(int j=i; j>0; j/=10)
			{
				if(j%10 == 3)
				{
					is = true;
					break;
				}
			}
			if(i%3 == 0)
			{
				is = true;
			}
			
			if(is)
			{
				System.out.print(" ");
				System.out.print(i);
			}
		}
		System.out.println("");
	}
} public class Main {
	public static void main(String[] args)
	{
		Scanner scanner = new Scanner(System.in);
		
		int n = scanner.nextInt();
		
		for(int i=1; i<=n; i++)
		{
			boolean is = false;
			for(int j=i; j>0; j/=10)
			{
				if(j%10 == 3)
				{
					is = true;
					break;
				}
			}
			if(i%3 == 0)
			{
				is = true;
			}
			
			if(is)
			{
				System.out.print(" ");
				System.out.print(i);
			}
		}
		System.out.println("");
	}
} Main
import java.util.Scanner;


public class Main {
	public static void main(String[] args)
	{
		Scanner scanner = new Scanner(System.in);
		
		int n = scanner.nextInt();
		
		for(int i=1; i<=n; i++)
		{
			boolean is = false;
			for(int j=i; j>0; j/=10)
			{
				if(j%10 == 3)
				{
					is = true;
					break;
				}
			}
			if(i%3 == 0)
			{
				is = true;
			}
			
			if(is)
			{
				System.out.print(" ");
				System.out.print(i);
			}
		}
		System.out.println("");
	}
}