import java.io.*;
import java.util.*;

public class Main
{
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int i,three,th_h,th_t;
		for(i=3;i<=x;i++)
		{
			three=i/10;
			th_h=i/100;
			th_t=i/1000;
			if(i%3==0)
			{
				System.out.printf(" %d",i);
			}
			else if((three%10==3)||(th_h%10==3)||(th_t%10==3)||(i%10==3))
			{
				System.out.printf(" %d",i);
			}
		}
		System.out.printf("\n");
	}
} import java.io.*; io.* java import java.util.*; util.* java public class Main
{
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int i,three,th_h,th_t;
		for(i=3;i<=x;i++)
		{
			three=i/10;
			th_h=i/100;
			th_t=i/1000;
			if(i%3==0)
			{
				System.out.printf(" %d",i);
			}
			else if((three%10==3)||(th_h%10==3)||(th_t%10==3)||(i%10==3))
			{
				System.out.printf(" %d",i);
			}
		}
		System.out.printf("\n");
	}
} Main public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int i,three,th_h,th_t;
		for(i=3;i<=x;i++)
		{
			three=i/10;
			th_h=i/100;
			th_t=i/1000;
			if(i%3==0)
			{
				System.out.printf(" %d",i);
			}
			else if((three%10==3)||(th_h%10==3)||(th_t%10==3)||(i%10==3))
			{
				System.out.printf(" %d",i);
			}
		}
		System.out.printf("\n");
	} main {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int i,three,th_h,th_t;
		for(i=3;i<=x;i++)
		{
			three=i/10;
			th_h=i/100;
			th_t=i/1000;
			if(i%3==0)
			{
				System.out.printf(" %d",i);
			}
			else if((three%10==3)||(th_h%10==3)||(th_t%10==3)||(i%10==3))
			{
				System.out.printf(" %d",i);
			}
		}
		System.out.printf("\n");
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int x = sc.nextInt(); x sc.nextInt() sc.nextInt sc int i i three three th_h th_h th_t; th_t for(i=3;i<=x;i++)
		{
			three=i/10;
			th_h=i/100;
			th_t=i/1000;
			if(i%3==0)
			{
				System.out.printf(" %d",i);
			}
			else if((three%10==3)||(th_h%10==3)||(th_t%10==3)||(i%10==3))
			{
				System.out.printf(" %d",i);
			}
		} i=3; i=3 i 3 i<=x i x i++ i++ i {
			three=i/10;
			th_h=i/100;
			th_t=i/1000;
			if(i%3==0)
			{
				System.out.printf(" %d",i);
			}
			else if((three%10==3)||(th_h%10==3)||(th_t%10==3)||(i%10==3))
			{
				System.out.printf(" %d",i);
			}
		} {
			three=i/10;
			th_h=i/100;
			th_t=i/1000;
			if(i%3==0)
			{
				System.out.printf(" %d",i);
			}
			else if((three%10==3)||(th_h%10==3)||(th_t%10==3)||(i%10==3))
			{
				System.out.printf(" %d",i);
			}
		} three=i/10 three i/10 i 10 th_h=i/100 th_h i/100 i 100 th_t=i/1000 th_t i/1000 i 1000 if(i%3==0)
			{
				System.out.printf(" %d",i);
			}
			else if((three%10==3)||(th_h%10==3)||(th_t%10==3)||(i%10==3))
			{
				System.out.printf(" %d",i);
			} i%3==0 i%3 i 3 0 {
				System.out.printf(" %d",i);
			} System.out.printf(" %d",i) System.out.printf System.out System System.out " %d" i if((three%10==3)||(th_h%10==3)||(th_t%10==3)||(i%10==3))
			{
				System.out.printf(" %d",i);
			} (three%10==3)||(th_h%10==3)||(th_t%10==3)||(i%10==3) (th_t%10==3) (three%10==3)||(th_h%10==3)||(th_t%10==3)||(i%10==3) (three%10==3) three%10 three 10 3 (th_h%10==3) th_h%10 th_h 10 3 (th_t%10==3) th_t%10 th_t 10 3 (i%10==3) i%10 i 10 3 {
				System.out.printf(" %d",i);
			} System.out.printf(" %d",i) System.out.printf System.out System System.out " %d" i System.out.printf("\n") System.out.printf System.out System System.out "\n" String[] args args public class Main
{
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int i,three,th_h,th_t;
		for(i=3;i<=x;i++)
		{
			three=i/10;
			th_h=i/100;
			th_t=i/1000;
			if(i%3==0)
			{
				System.out.printf(" %d",i);
			}
			else if((three%10==3)||(th_h%10==3)||(th_t%10==3)||(i%10==3))
			{
				System.out.printf(" %d",i);
			}
		}
		System.out.printf("\n");
	}
} public class Main
{
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int i,three,th_h,th_t;
		for(i=3;i<=x;i++)
		{
			three=i/10;
			th_h=i/100;
			th_t=i/1000;
			if(i%3==0)
			{
				System.out.printf(" %d",i);
			}
			else if((three%10==3)||(th_h%10==3)||(th_t%10==3)||(i%10==3))
			{
				System.out.printf(" %d",i);
			}
		}
		System.out.printf("\n");
	}
} Main
import java.io.*;
import java.util.*;

public class Main
{
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int i,three,th_h,th_t;
		for(i=3;i<=x;i++)
		{
			three=i/10;
			th_h=i/100;
			th_t=i/1000;
			if(i%3==0)
			{
				System.out.printf(" %d",i);
			}
			else if((three%10==3)||(th_h%10==3)||(th_t%10==3)||(i%10==3))
			{
				System.out.printf(" %d",i);
			}
		}
		System.out.printf("\n");
	}
}