import java.util.Scanner;

public class Main
{
    public static void main(String[] args)
    {
        int i=1;
        int jud=0;
        int x=0;
        Scanner sc=new Scanner(System.in);
        
        int n=sc.nextInt();
        
        while(true)
        {
            //CHECK_NUM
            if(jud==0)
            {
                i++;
                x=i;
            }
            
            if(x%3==0 && jud!=-1)
            {
                System.out.printf(" %d",i);
                jud=0;
            }
            else
            {
                if(x%10==3)
                {
                    System.out.printf(" %d",i);
                    jud=0;
                    //goto END_CHECK_NUM
                }
                else
                {
                    x/=10;
                    if(x!=0)
                    {
                        jud=-1;
                    }   //goto INCLUDE3
                    else
                    {
                        jud=0;
                    }
                }
            }
            
            //END_CHECK_NUM
            
            if(i+1>n)
            {
                break;
            }
            //goto CHECK_NUM
        }
        System.out.print("\n");
    }
} import java.util.Scanner; Scanner java.util public class Main
{
    public static void main(String[] args)
    {
        int i=1;
        int jud=0;
        int x=0;
        Scanner sc=new Scanner(System.in);
        
        int n=sc.nextInt();
        
        while(true)
        {
            //CHECK_NUM
            if(jud==0)
            {
                i++;
                x=i;
            }
            
            if(x%3==0 && jud!=-1)
            {
                System.out.printf(" %d",i);
                jud=0;
            }
            else
            {
                if(x%10==3)
                {
                    System.out.printf(" %d",i);
                    jud=0;
                    //goto END_CHECK_NUM
                }
                else
                {
                    x/=10;
                    if(x!=0)
                    {
                        jud=-1;
                    }   //goto INCLUDE3
                    else
                    {
                        jud=0;
                    }
                }
            }
            
            //END_CHECK_NUM
            
            if(i+1>n)
            {
                break;
            }
            //goto CHECK_NUM
        }
        System.out.print("\n");
    }
} Main public static void main(String[] args)
    {
        int i=1;
        int jud=0;
        int x=0;
        Scanner sc=new Scanner(System.in);
        
        int n=sc.nextInt();
        
        while(true)
        {
            //CHECK_NUM
            if(jud==0)
            {
                i++;
                x=i;
            }
            
            if(x%3==0 && jud!=-1)
            {
                System.out.printf(" %d",i);
                jud=0;
            }
            else
            {
                if(x%10==3)
                {
                    System.out.printf(" %d",i);
                    jud=0;
                    //goto END_CHECK_NUM
                }
                else
                {
                    x/=10;
                    if(x!=0)
                    {
                        jud=-1;
                    }   //goto INCLUDE3
                    else
                    {
                        jud=0;
                    }
                }
            }
            
            //END_CHECK_NUM
            
            if(i+1>n)
            {
                break;
            }
            //goto CHECK_NUM
        }
        System.out.print("\n");
    } main {
        int i=1;
        int jud=0;
        int x=0;
        Scanner sc=new Scanner(System.in);
        
        int n=sc.nextInt();
        
        while(true)
        {
            //CHECK_NUM
            if(jud==0)
            {
                i++;
                x=i;
            }
            
            if(x%3==0 && jud!=-1)
            {
                System.out.printf(" %d",i);
                jud=0;
            }
            else
            {
                if(x%10==3)
                {
                    System.out.printf(" %d",i);
                    jud=0;
                    //goto END_CHECK_NUM
                }
                else
                {
                    x/=10;
                    if(x!=0)
                    {
                        jud=-1;
                    }   //goto INCLUDE3
                    else
                    {
                        jud=0;
                    }
                }
            }
            
            //END_CHECK_NUM
            
            if(i+1>n)
            {
                break;
            }
            //goto CHECK_NUM
        }
        System.out.print("\n");
    } int i=1; i 1 int jud=0; jud 0 int x=0; x 0 Scanner sc=new Scanner(System.in); sc new Scanner(System.in) int n=sc.nextInt(); n sc.nextInt() sc.nextInt sc while(true)
        {
            //CHECK_NUM
            if(jud==0)
            {
                i++;
                x=i;
            }
            
            if(x%3==0 && jud!=-1)
            {
                System.out.printf(" %d",i);
                jud=0;
            }
            else
            {
                if(x%10==3)
                {
                    System.out.printf(" %d",i);
                    jud=0;
                    //goto END_CHECK_NUM
                }
                else
                {
                    x/=10;
                    if(x!=0)
                    {
                        jud=-1;
                    }   //goto INCLUDE3
                    else
                    {
                        jud=0;
                    }
                }
            }
            
            //END_CHECK_NUM
            
            if(i+1>n)
            {
                break;
            }
            //goto CHECK_NUM
        } true {
            //CHECK_NUM
            if(jud==0)
            {
                i++;
                x=i;
            }
            
            if(x%3==0 && jud!=-1)
            {
                System.out.printf(" %d",i);
                jud=0;
            }
            else
            {
                if(x%10==3)
                {
                    System.out.printf(" %d",i);
                    jud=0;
                    //goto END_CHECK_NUM
                }
                else
                {
                    x/=10;
                    if(x!=0)
                    {
                        jud=-1;
                    }   //goto INCLUDE3
                    else
                    {
                        jud=0;
                    }
                }
            }
            
            //END_CHECK_NUM
            
            if(i+1>n)
            {
                break;
            }
            //goto CHECK_NUM
        } if(jud==0)
            {
                i++;
                x=i;
            } jud==0 jud 0 {
                i++;
                x=i;
            } i++ i x=i x i if(x%3==0 && jud!=-1)
            {
                System.out.printf(" %d",i);
                jud=0;
            }
            else
            {
                if(x%10==3)
                {
                    System.out.printf(" %d",i);
                    jud=0;
                    //goto END_CHECK_NUM
                }
                else
                {
                    x/=10;
                    if(x!=0)
                    {
                        jud=-1;
                    }   //goto INCLUDE3
                    else
                    {
                        jud=0;
                    }
                }
            } x%3==0 && jud!=-1 x%3==0 x%3 x 3 0 jud!=-1 jud -1 1 {
                System.out.printf(" %d",i);
                jud=0;
            } System.out.printf(" %d",i) System.out.printf System.out System System.out " %d" i jud=0 jud 0 {
                if(x%10==3)
                {
                    System.out.printf(" %d",i);
                    jud=0;
                    //goto END_CHECK_NUM
                }
                else
                {
                    x/=10;
                    if(x!=0)
                    {
                        jud=-1;
                    }   //goto INCLUDE3
                    else
                    {
                        jud=0;
                    }
                }
            } if(x%10==3)
                {
                    System.out.printf(" %d",i);
                    jud=0;
                    //goto END_CHECK_NUM
                }
                else
                {
                    x/=10;
                    if(x!=0)
                    {
                        jud=-1;
                    }   //goto INCLUDE3
                    else
                    {
                        jud=0;
                    }
                } x%10==3 x%10 x 10 3 {
                    System.out.printf(" %d",i);
                    jud=0;
                    //goto END_CHECK_NUM
                } System.out.printf(" %d",i) System.out.printf System.out System System.out " %d" i jud=0 jud 0 {
                    x/=10;
                    if(x!=0)
                    {
                        jud=-1;
                    }   //goto INCLUDE3
                    else
                    {
                        jud=0;
                    }
                } x/=10 x 10 if(x!=0)
                    {
                        jud=-1;
                    }   //goto INCLUDE3
                    else
                    {
                        jud=0;
                    } x!=0 x 0 {
                        jud=-1;
                    } jud=-1 jud -1 1 {
                        jud=0;
                    } jud=0 jud 0 if(i+1>n)
            {
                break;
            } i+1>n i+1 i 1 n {
                break;
            } break; System.out.print("\n") System.out.print System.out System System.out "\n" String[] args args public class Main
{
    public static void main(String[] args)
    {
        int i=1;
        int jud=0;
        int x=0;
        Scanner sc=new Scanner(System.in);
        
        int n=sc.nextInt();
        
        while(true)
        {
            //CHECK_NUM
            if(jud==0)
            {
                i++;
                x=i;
            }
            
            if(x%3==0 && jud!=-1)
            {
                System.out.printf(" %d",i);
                jud=0;
            }
            else
            {
                if(x%10==3)
                {
                    System.out.printf(" %d",i);
                    jud=0;
                    //goto END_CHECK_NUM
                }
                else
                {
                    x/=10;
                    if(x!=0)
                    {
                        jud=-1;
                    }   //goto INCLUDE3
                    else
                    {
                        jud=0;
                    }
                }
            }
            
            //END_CHECK_NUM
            
            if(i+1>n)
            {
                break;
            }
            //goto CHECK_NUM
        }
        System.out.print("\n");
    }
} public class Main
{
    public static void main(String[] args)
    {
        int i=1;
        int jud=0;
        int x=0;
        Scanner sc=new Scanner(System.in);
        
        int n=sc.nextInt();
        
        while(true)
        {
            //CHECK_NUM
            if(jud==0)
            {
                i++;
                x=i;
            }
            
            if(x%3==0 && jud!=-1)
            {
                System.out.printf(" %d",i);
                jud=0;
            }
            else
            {
                if(x%10==3)
                {
                    System.out.printf(" %d",i);
                    jud=0;
                    //goto END_CHECK_NUM
                }
                else
                {
                    x/=10;
                    if(x!=0)
                    {
                        jud=-1;
                    }   //goto INCLUDE3
                    else
                    {
                        jud=0;
                    }
                }
            }
            
            //END_CHECK_NUM
            
            if(i+1>n)
            {
                break;
            }
            //goto CHECK_NUM
        }
        System.out.print("\n");
    }
} Main
import java.util.Scanner;

public class Main
{
    public static void main(String[] args)
    {
        int i=1;
        int jud=0;
        int x=0;
        Scanner sc=new Scanner(System.in);
        
        int n=sc.nextInt();
        
        while(true)
        {
            //CHECK_NUM
            if(jud==0)
            {
                i++;
                x=i;
            }
            
            if(x%3==0 && jud!=-1)
            {
                System.out.printf(" %d",i);
                jud=0;
            }
            else
            {
                if(x%10==3)
                {
                    System.out.printf(" %d",i);
                    jud=0;
                    //goto END_CHECK_NUM
                }
                else
                {
                    x/=10;
                    if(x!=0)
                    {
                        jud=-1;
                    }   //goto INCLUDE3
                    else
                    {
                        jud=0;
                    }
                }
            }
            
            //END_CHECK_NUM
            
            if(i+1>n)
            {
                break;
            }
            //goto CHECK_NUM
        }
        System.out.print("\n");
    }
}