import java.io.*;

class Main{
	public static void main (String[ ] args) throws Exception{
		BufferedReader br = new BufferedReader (new InputStreamReader (System.in));

		String str = br.readLine();
		int n = Integer.parseInt(str);

		for(int i = 1; i <= n; i++)
		{
			if(0 == i % 3)
			{
				System.out.print(" " + i);
			}
			else{
				int j = i;
				while(0 != j)
				{
					if(3 == j % 10)
					{
						System.out.print(" " + i);
						break;
					}
					j /= 10;
				}
			}
		}
		System.out.println("");
	}
} import java.io.*; io.* java class Main{
	public static void main (String[ ] args) throws Exception{
		BufferedReader br = new BufferedReader (new InputStreamReader (System.in));

		String str = br.readLine();
		int n = Integer.parseInt(str);

		for(int i = 1; i <= n; i++)
		{
			if(0 == i % 3)
			{
				System.out.print(" " + i);
			}
			else{
				int j = i;
				while(0 != j)
				{
					if(3 == j % 10)
					{
						System.out.print(" " + i);
						break;
					}
					j /= 10;
				}
			}
		}
		System.out.println("");
	}
} Main public static void main (String[ ] args) throws Exception{
		BufferedReader br = new BufferedReader (new InputStreamReader (System.in));

		String str = br.readLine();
		int n = Integer.parseInt(str);

		for(int i = 1; i <= n; i++)
		{
			if(0 == i % 3)
			{
				System.out.print(" " + i);
			}
			else{
				int j = i;
				while(0 != j)
				{
					if(3 == j % 10)
					{
						System.out.print(" " + i);
						break;
					}
					j /= 10;
				}
			}
		}
		System.out.println("");
	} main {
		BufferedReader br = new BufferedReader (new InputStreamReader (System.in));

		String str = br.readLine();
		int n = Integer.parseInt(str);

		for(int i = 1; i <= n; i++)
		{
			if(0 == i % 3)
			{
				System.out.print(" " + i);
			}
			else{
				int j = i;
				while(0 != j)
				{
					if(3 == j % 10)
					{
						System.out.print(" " + i);
						break;
					}
					j /= 10;
				}
			}
		}
		System.out.println("");
	} BufferedReader br = new BufferedReader (new InputStreamReader (System.in)); br new BufferedReader (new InputStreamReader (System.in)) String str = br.readLine(); str br.readLine() br.readLine br int n = Integer.parseInt(str); n Integer.parseInt(str) Integer.parseInt Integer str for(int i = 1; i <= n; i++)
		{
			if(0 == i % 3)
			{
				System.out.print(" " + i);
			}
			else{
				int j = i;
				while(0 != j)
				{
					if(3 == j % 10)
					{
						System.out.print(" " + i);
						break;
					}
					j /= 10;
				}
			}
		} int i = 1; int i = 1; i 1 i <= n i n i++ i++ i {
			if(0 == i % 3)
			{
				System.out.print(" " + i);
			}
			else{
				int j = i;
				while(0 != j)
				{
					if(3 == j % 10)
					{
						System.out.print(" " + i);
						break;
					}
					j /= 10;
				}
			}
		} {
			if(0 == i % 3)
			{
				System.out.print(" " + i);
			}
			else{
				int j = i;
				while(0 != j)
				{
					if(3 == j % 10)
					{
						System.out.print(" " + i);
						break;
					}
					j /= 10;
				}
			}
		} if(0 == i % 3)
			{
				System.out.print(" " + i);
			}
			else{
				int j = i;
				while(0 != j)
				{
					if(3 == j % 10)
					{
						System.out.print(" " + i);
						break;
					}
					j /= 10;
				}
			} 0 == i % 3 0 i % 3 i 3 {
				System.out.print(" " + i);
			} System.out.print(" " + i) System.out.print System.out System System.out " " + i " " i {
				int j = i;
				while(0 != j)
				{
					if(3 == j % 10)
					{
						System.out.print(" " + i);
						break;
					}
					j /= 10;
				}
			} int j = i; j i while(0 != j)
				{
					if(3 == j % 10)
					{
						System.out.print(" " + i);
						break;
					}
					j /= 10;
				} 0 != j 0 j {
					if(3 == j % 10)
					{
						System.out.print(" " + i);
						break;
					}
					j /= 10;
				} if(3 == j % 10)
					{
						System.out.print(" " + i);
						break;
					} 3 == j % 10 3 j % 10 j 10 {
						System.out.print(" " + i);
						break;
					} System.out.print(" " + i) System.out.print System.out System System.out " " + i " " i break; j /= 10 j 10 System.out.println("") System.out.println System.out System System.out "" String[ ] args args
import java.io.*;

class Main{
	public static void main (String[ ] args) throws Exception{
		BufferedReader br = new BufferedReader (new InputStreamReader (System.in));

		String str = br.readLine();
		int n = Integer.parseInt(str);

		for(int i = 1; i <= n; i++)
		{
			if(0 == i % 3)
			{
				System.out.print(" " + i);
			}
			else{
				int j = i;
				while(0 != j)
				{
					if(3 == j % 10)
					{
						System.out.print(" " + i);
						break;
					}
					j /= 10;
				}
			}
		}
		System.out.println("");
	}
}