import java.util.Scanner;

class Main{

/*	static boolean EndChk(int i, int n)
	{
		System.out.printf(" %d", i++);

		return ( (i<=n) ? true: false);
	}*/

	static int Include3(int x,int i)
	{
		while(x != 0)
		{
			if(x%10 == 3)
			{
				System.out.printf(" %d", i);
				break;
			}
			else
			{
				x = x/10;//goto EndChk
			}
		}

		return x;
	}

	public static void main(String[] args) {

		int n,i=1,x;

		Scanner scan = new Scanner(System.in);

		n = scan.nextInt();

		while(i <= n)
		{
			x = i;

			if(x%3 == 0)
			{
				System.out.printf(" %d", i);
			}
			else
			{
				x = Include3(x,i);//x???10??§?????£????????????3??????????????????0?????????
			}

			i++;
		}

		System.out.println();

	scan.close();
	}
} import java.util.Scanner; Scanner java.util class Main{

/*	static boolean EndChk(int i, int n)
	{
		System.out.printf(" %d", i++);

		return ( (i<=n) ? true: false);
	}*/

	static int Include3(int x,int i)
	{
		while(x != 0)
		{
			if(x%10 == 3)
			{
				System.out.printf(" %d", i);
				break;
			}
			else
			{
				x = x/10;//goto EndChk
			}
		}

		return x;
	}

	public static void main(String[] args) {

		int n,i=1,x;

		Scanner scan = new Scanner(System.in);

		n = scan.nextInt();

		while(i <= n)
		{
			x = i;

			if(x%3 == 0)
			{
				System.out.printf(" %d", i);
			}
			else
			{
				x = Include3(x,i);//x???10??§?????£????????????3??????????????????0?????????
			}

			i++;
		}

		System.out.println();

	scan.close();
	}
} Main static int Include3(int x,int i)
	{
		while(x != 0)
		{
			if(x%10 == 3)
			{
				System.out.printf(" %d", i);
				break;
			}
			else
			{
				x = x/10;//goto EndChk
			}
		}

		return x;
	} Include3 {
		while(x != 0)
		{
			if(x%10 == 3)
			{
				System.out.printf(" %d", i);
				break;
			}
			else
			{
				x = x/10;//goto EndChk
			}
		}

		return x;
	} while(x != 0)
		{
			if(x%10 == 3)
			{
				System.out.printf(" %d", i);
				break;
			}
			else
			{
				x = x/10;//goto EndChk
			}
		} x != 0 x 0 {
			if(x%10 == 3)
			{
				System.out.printf(" %d", i);
				break;
			}
			else
			{
				x = x/10;//goto EndChk
			}
		} if(x%10 == 3)
			{
				System.out.printf(" %d", i);
				break;
			}
			else
			{
				x = x/10;//goto EndChk
			} x%10 == 3 x%10 x 10 3 {
				System.out.printf(" %d", i);
				break;
			} System.out.printf(" %d", i) System.out.printf System.out System System.out " %d" i break; {
				x = x/10;//goto EndChk
			} x = x/10 x x/10 x 10 return x; x int x x int i i public static void main(String[] args) {

		int n,i=1,x;

		Scanner scan = new Scanner(System.in);

		n = scan.nextInt();

		while(i <= n)
		{
			x = i;

			if(x%3 == 0)
			{
				System.out.printf(" %d", i);
			}
			else
			{
				x = Include3(x,i);//x???10??§?????£????????????3??????????????????0?????????
			}

			i++;
		}

		System.out.println();

	scan.close();
	} main {

		int n,i=1,x;

		Scanner scan = new Scanner(System.in);

		n = scan.nextInt();

		while(i <= n)
		{
			x = i;

			if(x%3 == 0)
			{
				System.out.printf(" %d", i);
			}
			else
			{
				x = Include3(x,i);//x???10??§?????£????????????3??????????????????0?????????
			}

			i++;
		}

		System.out.println();

	scan.close();
	} int n n i=1 i 1 x; x Scanner scan = new Scanner(System.in); scan new Scanner(System.in) n = scan.nextInt() n scan.nextInt() scan.nextInt scan while(i <= n)
		{
			x = i;

			if(x%3 == 0)
			{
				System.out.printf(" %d", i);
			}
			else
			{
				x = Include3(x,i);//x???10??§?????£????????????3??????????????????0?????????
			}

			i++;
		} i <= n i n {
			x = i;

			if(x%3 == 0)
			{
				System.out.printf(" %d", i);
			}
			else
			{
				x = Include3(x,i);//x???10??§?????£????????????3??????????????????0?????????
			}

			i++;
		} x = i x i if(x%3 == 0)
			{
				System.out.printf(" %d", i);
			}
			else
			{
				x = Include3(x,i);//x???10??§?????£????????????3??????????????????0?????????
			} x%3 == 0 x%3 x 3 0 {
				System.out.printf(" %d", i);
			} System.out.printf(" %d", i) System.out.printf System.out System System.out " %d" i {
				x = Include3(x,i);//x???10??§?????£????????????3??????????????????0?????????
			} x = Include3(x,i) x Include3(x,i) Include3 x i i++ i System.out.println() System.out.println System.out System System.out scan.close() scan.close scan String[] args args
import java.util.Scanner;

class Main{

/*	static boolean EndChk(int i, int n)
	{
		System.out.printf(" %d", i++);

		return ( (i<=n) ? true: false);
	}*/

	static int Include3(int x,int i)
	{
		while(x != 0)
		{
			if(x%10 == 3)
			{
				System.out.printf(" %d", i);
				break;
			}
			else
			{
				x = x/10;//goto EndChk
			}
		}

		return x;
	}

	public static void main(String[] args) {

		int n,i=1,x;

		Scanner scan = new Scanner(System.in);

		n = scan.nextInt();

		while(i <= n)
		{
			x = i;

			if(x%3 == 0)
			{
				System.out.printf(" %d", i);
			}
			else
			{
				x = Include3(x,i);//x???10??§?????£????????????3??????????????????0?????????
			}

			i++;
		}

		System.out.println();

	scan.close();
	}
}