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

public class Main {
	public static void main(String[] args)throws IOException{
		InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(isr);
        
        	String list = br.readLine();
        	String an = null;
        	for (int i = 1; i <= Integer.parseInt(list); i++)
        	{
        		if (i % 3 == 0)
        			System.out.print(" " + i);
        		else
        		{
        			Integer oi = new Integer(i);
        			String suji = oi.toString();
        			char[] charsuji = suji.toCharArray();
        			for (int j = 0; j < suji.length(); j ++)
        			{
        				String newsuji = String.valueOf(charsuji[j]);
        				if (newsuji.equals("3"))
        				{
        					System.out.print(" " + i);
        				    break;
        				}
        			}
        		}
        	}
        	System.out.println();
	}

} 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 IOException{
		InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(isr);
        
        	String list = br.readLine();
        	String an = null;
        	for (int i = 1; i <= Integer.parseInt(list); i++)
        	{
        		if (i % 3 == 0)
        			System.out.print(" " + i);
        		else
        		{
        			Integer oi = new Integer(i);
        			String suji = oi.toString();
        			char[] charsuji = suji.toCharArray();
        			for (int j = 0; j < suji.length(); j ++)
        			{
        				String newsuji = String.valueOf(charsuji[j]);
        				if (newsuji.equals("3"))
        				{
        					System.out.print(" " + i);
        				    break;
        				}
        			}
        		}
        	}
        	System.out.println();
	}

} Main public static void main(String[] args)throws IOException{
		InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(isr);
        
        	String list = br.readLine();
        	String an = null;
        	for (int i = 1; i <= Integer.parseInt(list); i++)
        	{
        		if (i % 3 == 0)
        			System.out.print(" " + i);
        		else
        		{
        			Integer oi = new Integer(i);
        			String suji = oi.toString();
        			char[] charsuji = suji.toCharArray();
        			for (int j = 0; j < suji.length(); j ++)
        			{
        				String newsuji = String.valueOf(charsuji[j]);
        				if (newsuji.equals("3"))
        				{
        					System.out.print(" " + i);
        				    break;
        				}
        			}
        		}
        	}
        	System.out.println();
	} main {
		InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(isr);
        
        	String list = br.readLine();
        	String an = null;
        	for (int i = 1; i <= Integer.parseInt(list); i++)
        	{
        		if (i % 3 == 0)
        			System.out.print(" " + i);
        		else
        		{
        			Integer oi = new Integer(i);
        			String suji = oi.toString();
        			char[] charsuji = suji.toCharArray();
        			for (int j = 0; j < suji.length(); j ++)
        			{
        				String newsuji = String.valueOf(charsuji[j]);
        				if (newsuji.equals("3"))
        				{
        					System.out.print(" " + i);
        				    break;
        				}
        			}
        		}
        	}
        	System.out.println();
	} InputStreamReader isr = new InputStreamReader(System.in); isr new InputStreamReader(System.in) BufferedReader br = new BufferedReader(isr); br new BufferedReader(isr) String list = br.readLine(); list br.readLine() br.readLine br String an = null; an null for (int i = 1; i <= Integer.parseInt(list); i++)
        	{
        		if (i % 3 == 0)
        			System.out.print(" " + i);
        		else
        		{
        			Integer oi = new Integer(i);
        			String suji = oi.toString();
        			char[] charsuji = suji.toCharArray();
        			for (int j = 0; j < suji.length(); j ++)
        			{
        				String newsuji = String.valueOf(charsuji[j]);
        				if (newsuji.equals("3"))
        				{
        					System.out.print(" " + i);
        				    break;
        				}
        			}
        		}
        	} int i = 1; int i = 1; i 1 i <= Integer.parseInt(list) i Integer.parseInt(list) Integer.parseInt Integer list i++ i++ i {
        		if (i % 3 == 0)
        			System.out.print(" " + i);
        		else
        		{
        			Integer oi = new Integer(i);
        			String suji = oi.toString();
        			char[] charsuji = suji.toCharArray();
        			for (int j = 0; j < suji.length(); j ++)
        			{
        				String newsuji = String.valueOf(charsuji[j]);
        				if (newsuji.equals("3"))
        				{
        					System.out.print(" " + i);
        				    break;
        				}
        			}
        		}
        	} {
        		if (i % 3 == 0)
        			System.out.print(" " + i);
        		else
        		{
        			Integer oi = new Integer(i);
        			String suji = oi.toString();
        			char[] charsuji = suji.toCharArray();
        			for (int j = 0; j < suji.length(); j ++)
        			{
        				String newsuji = String.valueOf(charsuji[j]);
        				if (newsuji.equals("3"))
        				{
        					System.out.print(" " + i);
        				    break;
        				}
        			}
        		}
        	} if (i % 3 == 0)
        			System.out.print(" " + i);
        		else
        		{
        			Integer oi = new Integer(i);
        			String suji = oi.toString();
        			char[] charsuji = suji.toCharArray();
        			for (int j = 0; j < suji.length(); j ++)
        			{
        				String newsuji = String.valueOf(charsuji[j]);
        				if (newsuji.equals("3"))
        				{
        					System.out.print(" " + i);
        				    break;
        				}
        			}
        		} i % 3 == 0 i % 3 i 3 0 System.out.print(" " + i) System.out.print System.out System System.out " " + i " " i {
        			Integer oi = new Integer(i);
        			String suji = oi.toString();
        			char[] charsuji = suji.toCharArray();
        			for (int j = 0; j < suji.length(); j ++)
        			{
        				String newsuji = String.valueOf(charsuji[j]);
        				if (newsuji.equals("3"))
        				{
        					System.out.print(" " + i);
        				    break;
        				}
        			}
        		} Integer oi = new Integer(i); oi new Integer(i) String suji = oi.toString(); suji oi.toString() oi.toString oi char[] charsuji = suji.toCharArray(); charsuji suji.toCharArray() suji.toCharArray suji for (int j = 0; j < suji.length(); j ++)
        			{
        				String newsuji = String.valueOf(charsuji[j]);
        				if (newsuji.equals("3"))
        				{
        					System.out.print(" " + i);
        				    break;
        				}
        			} int j = 0; int j = 0; j 0 j < suji.length() j suji.length() suji.length suji j ++ j ++ j {
        				String newsuji = String.valueOf(charsuji[j]);
        				if (newsuji.equals("3"))
        				{
        					System.out.print(" " + i);
        				    break;
        				}
        			} {
        				String newsuji = String.valueOf(charsuji[j]);
        				if (newsuji.equals("3"))
        				{
        					System.out.print(" " + i);
        				    break;
        				}
        			} String newsuji = String.valueOf(charsuji[j]); newsuji String.valueOf(charsuji[j]) String.valueOf String charsuji[j] charsuji j if (newsuji.equals("3"))
        				{
        					System.out.print(" " + i);
        				    break;
        				} newsuji.equals("3") newsuji.equals newsuji "3" {
        					System.out.print(" " + i);
        				    break;
        				} System.out.print(" " + i) System.out.print System.out System System.out " " + i " " i break; System.out.println() System.out.println System.out System System.out String[] args args public class Main {
	public static void main(String[] args)throws IOException{
		InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(isr);
        
        	String list = br.readLine();
        	String an = null;
        	for (int i = 1; i <= Integer.parseInt(list); i++)
        	{
        		if (i % 3 == 0)
        			System.out.print(" " + i);
        		else
        		{
        			Integer oi = new Integer(i);
        			String suji = oi.toString();
        			char[] charsuji = suji.toCharArray();
        			for (int j = 0; j < suji.length(); j ++)
        			{
        				String newsuji = String.valueOf(charsuji[j]);
        				if (newsuji.equals("3"))
        				{
        					System.out.print(" " + i);
        				    break;
        				}
        			}
        		}
        	}
        	System.out.println();
	}

} public class Main {
	public static void main(String[] args)throws IOException{
		InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(isr);
        
        	String list = br.readLine();
        	String an = null;
        	for (int i = 1; i <= Integer.parseInt(list); i++)
        	{
        		if (i % 3 == 0)
        			System.out.print(" " + i);
        		else
        		{
        			Integer oi = new Integer(i);
        			String suji = oi.toString();
        			char[] charsuji = suji.toCharArray();
        			for (int j = 0; j < suji.length(); j ++)
        			{
        				String newsuji = String.valueOf(charsuji[j]);
        				if (newsuji.equals("3"))
        				{
        					System.out.print(" " + i);
        				    break;
        				}
        			}
        		}
        	}
        	System.out.println();
	}

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

public class Main {
	public static void main(String[] args)throws IOException{
		InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(isr);
        
        	String list = br.readLine();
        	String an = null;
        	for (int i = 1; i <= Integer.parseInt(list); i++)
        	{
        		if (i % 3 == 0)
        			System.out.print(" " + i);
        		else
        		{
        			Integer oi = new Integer(i);
        			String suji = oi.toString();
        			char[] charsuji = suji.toCharArray();
        			for (int j = 0; j < suji.length(); j ++)
        			{
        				String newsuji = String.valueOf(charsuji[j]);
        				if (newsuji.equals("3"))
        				{
        					System.out.print(" " + i);
        				    break;
        				}
        			}
        		}
        	}
        	System.out.println();
	}

}