#include<iostream>
#include<fstream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <math.h>
#include <vector>

using namespace std;

int main() {
    std::vector<int> v;

    int num=0,g,l,k1=0 ;

    bool s=false;
    bool b=false;
    bool c=true;
    bool y=true;

    cin>>g;

    for(int o=0;o<g;o++)
    {
        cin>>l;
        v.push_back(l);
    }

    int i=0;

    while(i<v.size())

    {
        y=true;
        bool h=false;
        c=true;
        int temp1=0,temp2=0,temp3=0 ;

        if(v.size()!=0 && v[i]==1)
        {
            b=true;
             temp1=0,temp2=0,temp3=0 ;
        for(int j=i+1;j<v.size();j++)
        {
            if(v[j]==3)
                c=false;
            if(c)
            {
            if(v[j]==1 && temp1==0)
                temp1=j;
            else if(v[j]==1 && temp2==0)
                temp2=j;
            else if(v[j]==1 && temp3==0)
                temp3=j;
            }
        }
        if(temp1!=0 && temp2==0 && temp3==0)
        {
            for(int j=i+1;j<v.size();j++)
            {
                if(v[j]==2)
                temp2=j;

            }

        }

        if(temp1!=0 && temp3==0  && temp2!=0)
        {
            v.erase(v.begin()+i);
            v.erase(v.begin()+temp1-1);
            v.erase(v.begin()+(temp2-2));
            num++;

        }

        if(temp1!=0 && temp3!=0 && temp2!=0)
        {
            v.erase(v.begin()+i);
            v.erase(v.begin()+temp1-1);
            v.erase(v.begin()+(temp2-2));
            v.erase(v.begin()+(temp3-3));
            num++;
        }

        }

        if(v.size()!=0 && v[i]==2)
        {

             temp1=0,temp2=0,temp3=0 ;

               if(temp1==0  && temp2==0)
         {
            for(int j=i+1;j<v.size();j++)
            {
                if( (v[j]==2 )&&(temp1==0))
                temp1=j;

            }

        }
               if(temp1!=0 &&  temp2==0)
        {
            v.erase(v.begin()+i);
            v.erase(v.begin()+temp1-1);
            num++;
            h=true;
        }   if(temp1==0 &&  temp2==0)
        {
            for(int j=i+1;j<v.size();j++)
            {
            if(v[j]==1 && temp1==0)
                temp1=j;
            else if(v[j]==1 && temp2==0)
                temp2=j;
            }
            if(temp1!=0 && temp2!=0)

            {

                v.erase(v.begin()+i);
            v.erase(v.begin()+temp1-1);
            v.erase(v.begin()+(temp2-2));
            num++;
            }
        }

                   if(temp1==0  && temp2==0)
         {
            for(int j=i+1;j<v.size();j++)
            {

                if(v[j]==1&&temp1==0)
                {
                temp1=j;

                s=true;
                }

            }

        }
        if(temp1!=0 &&  temp2==0 && s==true)
        {
            v.erase(v.begin()+i);
            v.erase(v.begin()+temp1-1);
            num++;
        }

        }

        if(v.size()!=0 && v[i]==1&& ( (temp1==0 && temp3==0 && temp2==0) || temp1!=0 && temp3==0 && temp2==0 )&& b)

        {
            if(h)
            {
                temp1=0,temp2=0,temp3=0 ;
            }

            if(temp1==0 && temp3==0 && temp2==0)
        {
            for(int j=i+1;j<v.size();j++)
            {
                if(v[j]==3 && temp1==0 )
                temp1=j;

            }
            for(int j=i+1;j<v.size();j++)
            {
                if(v[j]==2 && temp1==0 )
                temp1=j;

            }

        }
        if(temp1!=0 && temp3==0 && temp2==0)
        {
            v.erase(v.begin()+i);
            v.erase(v.begin()+temp1-1);
            num++;
        }
        }
        if(v.size()!=0 && v[i]==3)
        {
             temp1=0,temp2=0,temp3=0 ;
            for(int j=i+1;j<v.size();j++)
        {
            if(v[j]==1 && temp1==0)
                temp1=j;
        }
            if(temp1!=0)
        {
            v.erase(v.begin()+i);
            v.erase(v.begin()+temp1-1);
            num++;
        }
    }if(temp1==0)
        {
        v.erase(v.begin()+i);
        num++;
    }

    }

    cout<<num<<endl<<endl;
return 0;
}


#include<iostream>
#include<fstream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <math.h>
#include <vector>

using namespace std;

int main() {
    std::vector<int> v;

    int sum=0,g,l ;
    int counter1=0,counter2=0,counter3=0,counter4=0;

    bool s=false;
    bool b=false;
    bool c=true;
    bool y=true;

    cin>>g;

    for(int i=0;i<g;i++)
    {
        cin>>l;
        v.push_back(l);
    }

    for(int i=0;i<g;i++)
    {
        if(v[i]==1)
            counter1++ ;

    }

    for(int i=0;i<g;i++)
    {
        if(v[i]==2)
            counter2++ ;

    }
    for(int i=0;i<g;i++)
    {
        if(v[i]==3)
            counter3++ ;

    }

    for(int i=0;i<g;i++)
    {
        if(v[i]==4)
            counter4++ ;

    }
    sum+=counter4;

    if(counter3>0)
    {
        sum+=counter3;
        if(counter1<=counter3)
            counter1=0;
        else counter1=counter1-counter3;

    }

    if(counter2>0)
    {
        if(counter2%2==0)
            sum+=counter2/2;

        else if(counter1>1)
        {
            sum+=counter2/2;
            sum++;
            counter1=counter1-2;
        }
        else if(counter1==1)
        {
            sum+=counter2/2;
            sum++;
            counter1=counter1-1;
        }
        else sum+=( (counter2/2) + 1 ) ;
    }

    if(counter1>=4)
        sum+=(int)(ceil((float)(counter1 /4)));

    else if(counter1<4 && counter1>0)
        sum++;

    cout<<sum<<endl;

return 0;
}


#include<iostream>
#include<fstream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <math.h>
#include <vector>

using namespace std;

int main() {
    std::vector<int> v;

    int num=0,g,l,k1=0 ;

    bool s=false;
    bool b=false;
    bool c=true;

    cin>>g;

    for(int o=0;o<g;o++)
    {
        cin>>l;
        v.push_back(l);
    }

    int i=0;

    while(i<v.size())

    {
        bool h=false;
        c=true;
        int temp1=0,temp2=0,temp3=0 ;

        if(v.size()!=0 && v[i]==1)
        {
            b=true;
             temp1=0,temp2=0,temp3=0 ;
        for(int j=i+1;j<v.size();j++)
        {
            if(v[j]==3)
                c=false;
            if(c)
            {
            if(v[j]==1 && temp1==0)
                temp1=j;
            else if(v[j]==1 && temp2==0)
                temp2=j;
            else if(v[j]==1 && temp3==0)
                temp3=j;
            }
        }
        if(temp1!=0 && temp2==0 && temp3==0)
        {
            for(int j=i+1;j<v.size();j++)
            {
                if(v[j]==2)
                temp2=j;

            }

        }

        if(temp1!=0 && temp3==0  && temp2!=0)
        {
            v.erase(v.begin()+i);
            v.erase(v.begin()+temp1-1);
            v.erase(v.begin()+(temp2-2));
            num++;

        }

        if(temp1!=0 && temp3!=0 && temp2!=0)
        {
            v.erase(v.begin()+i);
            v.erase(v.begin()+temp1-1);
            v.erase(v.begin()+(temp2-2));
            v.erase(v.begin()+(temp3-3));
            num++;
        }

        }

        if(v.size()!=0 && v[i]==2)
        {

             temp1=0,temp2=0,temp3=0 ;

               if(temp1==0  && temp2==0)
         {
            for(int j=i+1;j<v.size();j++)
            {
                if( (v[j]==2 )&&(temp1==0))
                temp1=j;

            }

        }
               if(temp1!=0 &&  temp2==0)
        {
            v.erase(v.begin()+i);
            v.erase(v.begin()+temp1-1);
            num++;
            h=true;
        }
        /*         if(temp1==0  && temp2==0)
         {
            for(int j=i+1;j<v.size();j++)
            {
                if(v[j]==1&&temp1==0)
                {
                temp1=j;
                s=true;
                }

            }*/

               if(temp1==0 &&  temp2==0)
        {
            for(int j=i+1;j<v.size();j++)
            {
            if(v[j]==1 && temp1==0)
                temp1=j;
            else if(v[j]==1 && temp2==0)
                temp2=j;
            }

        }
        if(temp1!=0 &&  temp2==0 /*&& s==true*/)
        {
            v.erase(v.begin()+i);
            v.erase(v.begin()+temp1-1);
            num++;
        }
        /*if(temp1==0 &&  temp2==0)
        {
            for(int j=i+1;j<v.size();j++)
            {
            if(v[j]==1 && temp1==0)
                temp1=j;
            else if(v[j]==1 && temp2==0)
                temp2=j;
            }*/
            if(temp1!=0 && temp2!=0)

            {

                v.erase(v.begin()+i);
            v.erase(v.begin()+temp1-1);
            v.erase(v.begin()+(temp2-2));
            num++;
            }
        }

        if(v.size()!=0 && v[i]==1&& ( (temp1==0 && temp3==0 && temp2==0) || temp1!=0 && temp3==0 && temp2==0 )&& b)

        {
            if(h)
            {
                temp1=0,temp2=0,temp3=0 ;
            }

            if(temp1==0 && temp3==0 && temp2==0)
        {
            for(int j=i+1;j<v.size();j++)
            {
                if(v[j]==3 && temp1==0 )
                temp1=j;

            }
            for(int j=i+1;j<v.size();j++)
            {
                if(v[j]==2 && temp1==0 )
                temp1=j;

            }

        }
        if(temp1!=0 && temp3==0 && temp2==0)
        {
            v.erase(v.begin()+i);
            v.erase(v.begin()+temp1-1);
            num++;
        }
        }
        if(v.size()!=0 && v[i]==3)
        {
             temp1=0,temp2=0,temp3=0 ;
            for(int j=i+1;j<v.size();j++)
        {
            if(v[j]==1 && temp1==0)
                temp1=j;
        }
            if(temp1!=0)
        {
            v.erase(v.begin()+i);
            v.erase(v.begin()+temp1-1);
            num++;
        }
    }if(temp1==0)
        {
        v.erase(v.begin()+i);
        num++;
    }

    }

    cout<<num<<endl;
return 0;
}


#include<iostream>
#include<fstream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <math.h>
#include <vector>

using namespace std;

int main() {
    std::vector<int> v;

    int sum=0,g,l ;
    int counter1=0,counter2=0,counter3=0,counter4=0;

    bool s=false;
    bool b=false;
    bool c=true;
    bool y=true;

    cin>>g;

    for(int i=0;i<g;i++)
    {
        cin>>l;
        v.push_back(l);
    }

    for(int i=0;i<g;i++)
    {
        if(v[i]==1)
            counter1++ ;

    }

    for(int i=0;i<g;i++)
    {
        if(v[i]==2)
            counter2++ ;

    }
    for(int i=0;i<g;i++)
    {
        if(v[i]==3)
            counter3++ ;

    }

    for(int i=0;i<g;i++)
    {
        if(v[i]==4)
            counter4++ ;

    }
    sum+=counter4;

    if(counter3>0)
    {
        sum+=counter3;
        if(counter1<=counter3)
            counter1=0;
        else counter1=counter1-counter3;

    }

    if(counter2>0)
    {
        if(counter2%2==0)
            sum+=counter2/2;
        else if(counter1>1)
        {
            sum++;
            counter1=counter1-2;
        }
        else if(counter1==1)
        {
            sum++;
            counter1=counter1-1;
        }
        else sum+=counter2/2 + 1 ;
    }
    if(counter1>4)
        sum+=ceil((float)(counter1 /4));
    else if(counter1<4 && counter1>0)
        sum++;
    cout<<sum<<endl;

return 0;
}


#include<iostream>
#include<fstream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <math.h>
#include <vector>

using namespace std;

int main() {
    std::vector<int> v;

    int sum=0,g,l ;
    int counter1=0,counter2=0,counter3=0,counter4=0;

    bool s=false;
    bool b=false;
    bool c=true;
    bool y=true;

    cin>>g;

    for(int i=0;i<g;i++)
    {
        cin>>l;
        v.push_back(l);
    }

    for(int i=0;i<g;i++)
    {
        if(v[i]==1)
            counter1++ ;

    }

    for(int i=0;i<g;i++)
    {
        if(v[i]==2)
            counter2++ ;

    }
    for(int i=0;i<g;i++)
    {
        if(v[i]==3)
            counter3++ ;

    }

    for(int i=0;i<g;i++)
    {
        if(v[i]==4)
            counter4++ ;

    }
    sum+=counter4;

    if(counter3>0)
    {
        sum+=counter3;
        if(counter1<=counter3)
            counter1=0;
        else counter1=counter1-counter3;

    }

    if(counter2>0)
    {
        if(counter2%2==0)
            sum+=counter2/2;
        else if(counter1>1)
        {
            sum+=counter2/2 +1;
            counter1=counter1-2;
        }
        else if(counter1==1)
        {
            sum+=counter2/2 + 1;
            counter1=counter1-1;
        }
        else sum+=counter2/2 + 1 ;
    }
    if(counter1>4)
        sum+=ceil((float)(counter1 /4));
    else if(counter1>0)
        sum++;
    cout<<sum<<endl;

return 0;
}


#include<iostream>
#include<fstream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <math.h>
#include <vector>

using namespace std;

int main() {
    std::vector<int> v;

    int sum=0,g,l ;
    int counter1=0,counter2=0,counter3=0,counter4=0;

    bool s=false;
    bool b=false;
    bool c=true;
    bool y=true;

    cin>>g;

    for(int i=0;i<g;i++)
    {
        cin>>l;
        v.push_back(l);
    }

    for(int i=0;i<g;i++)
    {
        if(v[i]==1)
            counter1++ ;

    }

    for(int i=0;i<g;i++)
    {
        if(v[i]==2)
            counter2++ ;

    }
    for(int i=0;i<g;i++)
    {
        if(v[i]==3)
            counter3++ ;

    }

    for(int i=0;i<g;i++)
    {
        if(v[i]==4)
            counter4++ ;

    }
    sum+=counter4;

    if(counter3>0)
    {
        sum+=counter3;
        if(counter1<=counter3)
            counter1=0;
        else counter1=counter1-counter3;

    }

    if(counter2>0)
    {
        if(counter2%2==0)

            sum+=(counter2/2);

        else if(counter1>1)
        {
            sum+=counter2/2;
            sum++;
            counter1=counter1-2;
        }
        else if(counter1==1)
        {
            sum+=counter2/2;
            sum++;
            counter1=counter1-1;
        }
        else sum=sum+( (counter2/4) + 1 ) ;
    }

    if(counter1>=4)
        sum+=(int)(ceil((float)(counter1 /4)));

    else if(counter1<4 && counter1>0)
        sum++;

    cout<<sum<<endl;

return 0;
}


#include<iostream>
#include<fstream>
#include <stdio.h>
#include <stdlib.h>
#include <string>

#include <vector>

using namespace std;

int main() {
    std::vector<int> v;

    int num=0,g,l,k1=0 ;

    bool s=false;
    bool b=false;
    bool c=true;
    cin>>g;

    for(int o=0;o<g;o++)
    {
        cin>>l;
        v.push_back(l);
    }

    int i=0;
    while(i<v.size())

    {
        int temp1=0,temp2=0,temp3=0 ;

        if(v.size()!=0 && v[i]==1)
        {
            b=true;
             temp1=0,temp2=0,temp3=0 ;
        for(int j=i+1;j<v.size();j++)
        {
            if(v[j]==3)
                c=false;
            if(c)
            {
            if(v[j]==1 && temp1==0)
                temp1=j;
            else if(v[j]==1 && temp2==0)
                temp2=j;
            else if(v[j]==1 && temp3==0)
                temp3=j;
            }
        }
        if(temp1!=0 && temp2==0 && temp3==0)
        {
            for(int j=i+1;j<v.size();j++)
            {
                if(v[j]==2)
                temp2=j;

            }

        }

        if(temp1!=0 && temp3==0  && temp2!=0)
        {
            v.erase(v.begin()+i);
            v.erase(v.begin()+temp1-1);
            v.erase(v.begin()+(temp2-2));
            num++;

        }

        if(temp1!=0 && temp3!=0 && temp2!=0)
        {
            v.erase(v.begin()+i);
            v.erase(v.begin()+temp1-1);
            v.erase(v.begin()+(temp2-2));
            v.erase(v.begin()+(temp3-3));
            num++;
        }

        }

        if(v.size()!=0 && v[i]==2)
        {

             temp1=0,temp2=0,temp3=0 ;

               if(temp1==0  && temp2==0)
         {
            for(int j=i+1;j<v.size();j++)
            {
                if( (v[j]==2 )&&(temp1==0))
                temp1=j;

            }

        }
               if(temp1!=0 &&  temp2==0)
        {
            v.erase(v.begin()+i);
            v.erase(v.begin()+temp1-1);
            num++;
        }
                   if(temp1==0  && temp2==0)
         {
            for(int j=i+1;j<v.size();j++)
            {
                if(v[j]==1&&temp1==0)
                {
                temp1=j;
                s=true;
                }

            }

        }
        if(temp1!=0 &&  temp2==0 && s==true)
        {
            v.erase(v.begin()+i);
            v.erase(v.begin()+temp1-1);
            num++;
        }
        if(temp1==0 &&  temp2==0)
        {
            for(int j=i+1;j<v.size();j++)
            {
            if(v[j]==1 && temp1==0)
                temp1=j;
            else if(v[j]==1 && temp2==0)
                temp2=j;
            }
            if(temp1!=0 && temp2!=0)

            {
                v.erase(v.begin()+i);
            v.erase(v.begin()+temp1-1);
            v.erase(v.begin()+(temp2-2));
            num++;
            }
        }

        }

        if(v.size()!=0 && v[i]==1&& ( (temp1==0 && temp3==0 && temp2==0) || temp1!=0 && temp3==0 && temp2==0 )&& b)

        {
            if(temp1==0 && temp3==0 && temp2==0)
        {
            for(int j=i+1;j<v.size();j++)
            {
                if(v[j]==3 && temp1==0 )
                temp1=j;

            }

        }
        if(temp1!=0 && temp3==0 && temp2==0)
        {
            v.erase(v.begin()+i);
            v.erase(v.begin()+temp1-1);
            num++;
        }
        }
        if(v.size()!=0 && v[i]==3)
        {
             temp1=0,temp2=0,temp3=0 ;
            for(int j=i+1;j<v.size();j++)
        {
            if(v[j]==1 && temp1==0)
                temp1=j;
        }
            if(temp1!=0)
        {
            v.erase(v.begin()+i);
            v.erase(v.begin()+temp1-1);
            num++;
        }
    }if(temp1==0)
        {
        v.erase(v.begin()+i);
        num++;
    }

    }
    cout<<num<<endl;
return 0;
}


#include<iostream>
#include<fstream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <math.h>
#include <vector>

using namespace std;

int main() {
    std::vector<int> v;

    int num=0,g,l,k1=0 ;

    bool s=false;
    cin>>g;

    for(int o=0;o<g;o++)
    {
        cin>>l;
        v.push_back(l);
    }

    int i=0;
    while(i<v.size())

    {
        int temp1=0,temp2=0,temp3=0 ;

        if(v[i]==1)
        {
             temp1=0,temp2=0,temp3=0 ;
        for(int j=i+1;j<v.size();j++)
        {
            if(v[j]==1 && temp1==0)
                temp1=j;
            else if(v[j]==1 && temp2==0)
                temp2=j;
            else if(v[j]==1 && temp3==0)
                temp3=j;

        }
        if(temp1!=0 && temp2==0 && temp3==0)
        {
            for(int j=i+1;j<v.size();j++)
            {
                if(v[j]==2)
                temp2=j;

            }

        }

        if(temp1!=0 && temp3==0  && temp2!=0)
        {
            v.erase(v.begin()+i);
            v.erase(v.begin()+temp1-1);
            v.erase(v.begin()+(temp2-2));
            num++;

        }

        if(temp1!=0 && temp3!=0 && temp2!=0)
        {
            v.erase(v.begin()+i);
            v.erase(v.begin()+temp1-1);
            v.erase(v.begin()+(temp2-2));
            v.erase(v.begin()+(temp3-3));
            num++;
        }

        }

        if(v[i]==2)
        {

             temp1=0,temp2=0,temp3=0 ;

               if(temp1==0  && temp2==0)
         {
            for(int j=i+1;j<v.size();j++)
            {
                if( (v[j]==2 )&&(temp1==0))
                temp1=j;

            }

        }
               if(temp1!=0 &&  temp2==0)
        {
            v.erase(v.begin()+i);
            v.erase(v.begin()+temp1-1);
            num++;
        }
                   if(temp1==0  && temp2==0)
         {
            for(int j=i+1;j<v.size();j++)
            {
                if(v[j]==1&&temp1==0)
                {
                temp1=j;
                s=true;
                }

            }

        }
        if(temp1!=0 &&  temp2==0 && s==true)
        {
            v.erase(v.begin()+i);
            v.erase(v.begin()+temp1-1);
            num++;
        }
        if(temp1==0 &&  temp2==0)
        {
            for(int j=i+1;j<v.size();j++)
            {
            if(v[j]==1 && temp1==0)
                temp1=j;
            else if(v[j]==1 && temp2==0)
                temp2=j;
            }
            if(temp1!=0 && temp2!=0)

            {
                v.erase(v.begin()+i);
            v.erase(v.begin()+temp1-1);
            v.erase(v.begin()+(temp2-2));
            num++;
            }
        }

        }

        if(v[i]==1&& ( (temp1==0 && temp3==0 && temp2==0) || temp1!=0 && temp3==0 && temp2==0 ))

        {
            if(temp1==0 && temp3==0 && temp2==0)
        {
            for(int j=i+1;j<v.size();j++)
            {
                if(v[j]==3 && temp1==0 )
                temp1=j;

            }

        }
        if(temp1!=0 && temp3==0 && temp2==0)
        {
            v.erase(v.begin()+i);
            v.erase(v.begin()+temp1-1);
            num++;
        }
        }
        if(v[i]==3)
        {
             temp1=0,temp2=0,temp3=0 ;
            for(int j=i+1;j<v.size();j++)
        {
            if(v[j]==1 && temp1==0)
                temp1=j;
        }
            if(temp1!=0)
        {
            v.erase(v.begin()+i);
            v.erase(v.begin()+temp1-1);
            num++;
        }
    }if(temp1==0)
        {
        v.erase(v.begin()+i);
        num++;
    }

    }
    cout<<num<<endl;
return 0;
}


#include<iostream>
#include<fstream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <math.h>
#include <vector>

using namespace std;

int main() {
    std::vector<int> v;

    int num=0,g,l,k1=0 ;

    bool s=false;
    cin>>g;

    for(int o=0;o<g;o++)
    {
        cin>>l;
        v.push_back(l);
    }

    int i=0;
    while(i<v.size())

    {
        int temp1=0,temp2=0,temp3=0 ;

        if(v.size()!=0 && v[i]==1)
        {
             temp1=0,temp2=0,temp3=0 ;
        for(int j=i+1;j<v.size();j++)
        {
            if(v[j]==1 && temp1==0)
                temp1=j;
            else if(v[j]==1 && temp2==0)
                temp2=j;
            else if(v[j]==1 && temp3==0)
                temp3=j;

        }
        if(temp1!=0 && temp2==0 && temp3==0)
        {
            for(int j=i+1;j<v.size();j++)
            {
                if(v[j]==2)
                temp2=j;

            }

        }

        if(temp1!=0 && temp3==0  && temp2!=0)
        {
            v.erase(v.begin()+i);
            v.erase(v.begin()+temp1-1);
            v.erase(v.begin()+(temp2-2));
            num++;

        }

        if(temp1!=0 && temp3!=0 && temp2!=0)
        {
            v.erase(v.begin()+i);
            v.erase(v.begin()+temp1-1);
            v.erase(v.begin()+(temp2-2));
            v.erase(v.begin()+(temp3-3));
            num++;
        }

        }

        if(v.size()!=0 && v[i]==2)
        {

             temp1=0,temp2=0,temp3=0 ;

               if(temp1==0  && temp2==0)
         {
            for(int j=i+1;j<v.size();j++)
            {
                if( (v[j]==2 )&&(temp1==0))
                temp1=j;

            }

        }
               if(temp1!=0 &&  temp2==0)
        {
            v.erase(v.begin()+i);
            v.erase(v.begin()+temp1-1);
            num++;
        }
                   if(temp1==0  && temp2==0)
         {
            for(int j=i+1;j<v.size();j++)
            {
                if(v[j]==1&&temp1==0)
                {
                temp1=j;
                s=true;
                }

            }

        }
        if(temp1!=0 &&  temp2==0 && s==true)
        {
            v.erase(v.begin()+i);
            v.erase(v.begin()+temp1-1);
            num++;
        }
        if(temp1==0 &&  temp2==0)
        {
            for(int j=i+1;j<v.size();j++)
            {
            if(v[j]==1 && temp1==0)
                temp1=j;
            else if(v[j]==1 && temp2==0)
                temp2=j;
            }
            if(temp1!=0 && temp2!=0)

            {
                v.erase(v.begin()+i);
            v.erase(v.begin()+temp1-1);
            v.erase(v.begin()+(temp2-2));
            num++;
            }
        }

        }

        if(v.size()!=0 && v[i]==1&& ( (temp1==0 && temp3==0 && temp2==0) || temp1!=0 && temp3==0 && temp2==0 ))

        {
            if(temp1==0 && temp3==0 && temp2==0)
        {
            for(int j=i+1;j<v.size();j++)
            {
                if(v[j]==3 && temp1==0 )
                temp1=j;

            }

        }
        if(temp1!=0 && temp3==0 && temp2==0)
        {
            v.erase(v.begin()+i);
            v.erase(v.begin()+temp1-1);
            num++;
        }
        }
        if(v.size()!=0 && v[i]==3)
        {
             temp1=0,temp2=0,temp3=0 ;
            for(int j=i+1;j<v.size();j++)
        {
            if(v[j]==1 && temp1==0)
                temp1=j;
        }
            if(temp1!=0)
        {
            v.erase(v.begin()+i);
            v.erase(v.begin()+temp1-1);
            num++;
        }
    }if(temp1==0)
        {
        v.erase(v.begin()+i);
        num++;
    }

    }
    cout<<num<<endl;
return 0;
}


#include<iostream>
#include<fstream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <math.h>
#include <vector>

using namespace std;

int main() {
    std::vector<int> v;

    int sum=0,g,l ;
    int counter1=0,counter2=0,counter3=0,counter4=0;

    bool s=false;
    bool b=false;
    bool c=true;
    bool y=true;

    cin>>g;

    for(int i=0;i<g;i++)
    {
        cin>>l;
        v.push_back(l);
    }

    for(int i=0;i<g;i++)
    {
        if(v[i]==1)
            counter1++ ;

    }

    for(int i=0;i<g;i++)
    {
        if(v[i]==2)
            counter2++ ;

    }
    for(int i=0;i<g;i++)
    {
        if(v[i]==3)
            counter3++ ;

    }

    for(int i=0;i<g;i++)
    {
        if(v[i]==4)
            counter4++ ;

    }
    sum+=counter4;

    if(counter3>0)
    {
        sum+=counter3;
        if(counter1<=counter3)
            counter1=0;
        else counter1=counter1-counter3;

    }

    if(counter2>0)
    {
        if(counter2%2==0)

            sum+=(counter2/2);

        else if(counter1>1)
        {
            sum+=counter2/2;
            sum++;
            counter1=counter1-2;
        }
        else if(counter1==1)
        {
            sum+=counter2/4;
            sum++;
            counter1=counter1-1;
        }
        else sum=sum+( (counter2/4) + 1 ) ;
    }

    if(counter1>=4)
        sum+=(int)(ceil((float)(counter1 /4)));

    else if(counter1<4 && counter1>0)
        sum++;

    cout<<sum<<endl;

return 0;
}


#include<iostream>
#include<fstream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <math.h>
#include <vector>

using namespace std;

int main() {
    std::vector<int> v;

    int sum=0,g,l ;
    int counter1=0,counter2=0,counter3=0,counter4=0;

    bool s=false;
    bool b=false;
    bool c=true;
    bool y=true;

    cin>>g;

    for(int i=0;i<g;i++)
    {
        cin>>l;
        v.push_back(l);
    }

    for(int i=0;i<g;i++)
    {
        if(v[i]==1)
            counter1++ ;

    }

    for(int i=0;i<g;i++)
    {
        if(v[i]==2)
            counter2++ ;

    }
    for(int i=0;i<g;i++)
    {
        if(v[i]==3)
            counter3++ ;

    }

    for(int i=0;i<g;i++)
    {
        if(v[i]==4)
            counter4++ ;

    }
    sum+=counter4;

    if(counter3>0)
    {
        sum+=counter3;
        if(counter1<=counter3)
            counter1=0;
        else counter1=counter3-counter1;

    }

    if(counter2>0)
    {
        if(counter2%2==0)
            sum+=counter2/2;
        else if(counter1>1)
        {
            sum+=counter2/2 +2;
            counter1=counter1-2;
        }
        else if(counter1==1)
        {
            sum+=counter2/2 + 1;
            counter1=counter1-1;
        }
        else sum+=counter2/2 + 1 ;
    }
    if(counter1>4)
        sum+=ceil((float)(counter1 /4));
    else if(counter1>0)
        sum++;
    cout<<sum<<endl;

return 0;
}


#include<iostream>
#include<fstream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <math.h>
#include <vector>

using namespace std;

int main() {
    std::vector<int> v;

    int sum=0,g,l ;
    int counter1=0,counter2=0,counter3=0,counter4=0;

    bool s=false;
    bool b=false;
    bool c=true;
    bool y=true;

    cin>>g;

    for(int i=0;i<g;i++)
    {
        cin>>l;
        v.push_back(l);
    }

    for(int i=0;i<g;i++)
    {
        if(v[i]==1)
            counter1++ ;

    }

    for(int i=0;i<g;i++)
    {
        if(v[i]==2)
            counter2++ ;

    }
    for(int i=0;i<g;i++)
    {
        if(v[i]==3)
            counter3++ ;

    }

    for(int i=0;i<g;i++)
    {
        if(v[i]==4)
            counter4++ ;

    }
    sum+=counter4;

    if(counter3>0)
    {
        sum+=counter3;
        if(counter1<=counter3)
            counter1=0;
        else counter1=counter1-counter3;

    }

    if(counter2>0)
    {
        if(counter2%2==0)
            sum+=counter2/2;

        else if(counter1>1)
        {
            sum+=counter2/2;
            sum++;
            counter1=counter1-2;
        }
        else if(counter1==1)
        {
            sum+=counter2/2;
            sum++;
            counter1=counter1-1;
        }
        else sum+=counter2/2 + 1 ;
    }
    if(counter1>=4)
        sum+=ceil((float)(counter1 /4));

    else if(counter1<4 && counter1>0)
        sum++;

    cout<<sum<<endl;

return 0;
}


#include<iostream>
#include<fstream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <math.h>
#include <vector>

using namespace std;

int main() {
    std::vector<int> v;

    int sum=0,g,l ;
    int counter1=0,counter2=0,counter3=0,counter4=0;

    bool s=false;
    bool b=false;
    bool c=true;
    bool y=true;

    cin>>g;

    for(int i=0;i<g;i++)
    {
        cin>>l;
        v.push_back(l);
    }

    for(int i=0;i<g;i++)
    {
        if(v[i]==1)
            counter1++ ;

    }

    for(int i=0;i<g;i++)
    {
        if(v[i]==2)
            counter2++ ;

    }
    for(int i=0;i<g;i++)
    {
        if(v[i]==3)
            counter3++ ;

    }

    for(int i=0;i<g;i++)
    {
        if(v[i]==4)
            counter4++ ;

    }
    sum+=counter4;

    if(counter3>0)
    {
        sum+=counter3;
        if(counter1<=counter3)
            counter1=0;
        else counter1=counter1-counter3;

    }

    if(counter2>0)
    {
        if(counter2%2==0)
            sum+=counter2/2;

        else if(counter1>1)
        {
            sum+=counter2/2;
            sum++;
            counter1=counter1-2;
        }
        else if(counter1==1)
        {
            sum+=counter2/2;
            sum++;
            counter1=counter1-1;
        }
        else sum+=counter2/2 + 1 ;
    }
    if(counter1>=4)
        sum+=ceil((float)(counter1 /4));

    else if(counter1<4 && counter1>0)
        sum++;

    cout<<sum;

return 0;
}


#include<iostream>
#include<fstream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <math.h>
#include <vector>

using namespace std;

int main() {
    std::vector<int> v;

    int num=0,g,l,k1=0 ;

    bool s=false;
    bool b=false;
    bool c=true;
    bool y=true;

    cin>>g;

    for(int o=0;o<g;o++)
    {
        cin>>l;
        v.push_back(l);
    }

    int i=0;

    while(i<v.size())

    {
        y=true;

        bool h=false;
        c=true;
        int temp1=0,temp2=0,temp3=0 ;

        if(v.size()!=0 && v[i]==1)
        {
            b=true;
             temp1=0,temp2=0,temp3=0 ;
        for(int j=i+1;j<v.size();j++)
        {
            if(v[j]==3 && temp3==0)
            {

                c=false;
                temp2=0;
                temp1=0;
            }
            if(c)
            {
            if(v[j]==1 && temp1==0)
            {
                temp1=j;

            }
            else if(v[j]==1 && temp2==0)
            {
                temp2=j;

            }
            else if(v[j]==1 && temp3==0)
                temp3=j;
            }
        }
        if(temp1!=0 && temp2==0 && temp3==0)
        {
            for(int j=i+1;j<v.size();j++)
            {
                if(v[j]==2)
                temp2=j;

            }

        }

        if(temp1!=0 && temp3==0  && temp2!=0)
        {
            v.erase(v.begin()+i);
            v.erase(v.begin()+temp1-1);
            v.erase(v.begin()+(temp2-2));
            num++;

        }

        if(temp1!=0 && temp3!=0 && temp2!=0)
        {
            v.erase(v.begin()+i);
            v.erase(v.begin()+temp1-1);
            v.erase(v.begin()+(temp2-2));
            v.erase(v.begin()+(temp3-3));
            num++;
        }

        }

        if(v.size()!=0 && v[i]==2)
        {

             temp1=0,temp2=0,temp3=0 ;

               if(temp1==0  && temp2==0)
         {
            for(int j=i+1;j<v.size();j++)
            {
                if( (v[j]==2 )&&(temp1==0))
                temp1=j;

            }

        }
               if(temp1!=0 &&  temp2==0)
        {
            v.erase(v.begin()+i);
            v.erase(v.begin()+temp1-1);
            num++;
            h=true;
        }

            if(temp1==0 &&  temp2==0)
        {
            for(int j=i+1;j<v.size();j++)
            {
            if(v[j]==1 && temp1==0)
                temp1=j;
            else if(v[j]==1 && temp2==0)
                temp2=j;
            if(temp2==0)
                s=true;
            }
            if(temp1!=0 && temp2!=0)

            {

            v.erase(v.begin()+i);
            v.erase(v.begin()+temp1-1);
            v.erase(v.begin()+(temp2-2));
            num++;
            }
        }
            if(temp1!=0 &&  temp2==0 && s)
        {
            v.erase(v.begin()+i);
            v.erase(v.begin()+temp1-1);
            num++;
        }

        }

        if(v.size()!=0 && v[i]==1&& ( (temp1==0 && temp3==0 && temp2==0) || temp1!=0 && temp3==0 && temp2==0 )&& b)

        {
            if(h)
            {
                temp1=0,temp2=0,temp3=0 ;
            }

            if(temp1==0 && temp3==0 && temp2==0)
        {
            for(int j=i+1;j<v.size();j++)
            {
                if(v[j]==3 && temp1==0 )
                temp1=j;

            }
            for(int j=i+1;j<v.size();j++)
            {
                if(v[j]==2 && temp1==0 )
                temp1=j;

            }

        }
        if(temp1!=0 && temp3==0 && temp2==0)
        {
            v.erase(v.begin()+i);
            v.erase(v.begin()+temp1-1);
            num++;
        }
        }
        if(v.size()!=0 && v[i]==3)
        {
             temp1=0,temp2=0,temp3=0 ;
            for(int j=i+1;j<v.size();j++)
        {
            if(v[j]==1 && temp1==0)
                temp1=j;
        }
            if(temp1!=0)
        {
            v.erase(v.begin()+i);
            v.erase(v.begin()+temp1-1);
            num++;
        }
    }if(temp1==0)
        {
        v.erase(v.begin()+i);
        num++;
    }

    }

    cout<<num;
return 0;
}


#include<iostream>
#include<fstream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <math.h>
#include <vector>

using namespace std;

int main() {
    std::vector<int> v;

    int sum=0,g,l ;
    int counter1=0,counter2=0,counter3=0,counter4=0;

    bool s=false;
    bool b=false;
    bool c=true;
    bool y=true;

    cin>>g;

    for(int i=0;i<g;i++)
    {
        cin>>l;
        v.push_back(l);
    }

    for(int i=0;i<g;i++)
    {
        if(v[i]==1)
            counter1++ ;

    }

    for(int i=0;i<g;i++)
    {
        if(v[i]==2)
            counter2++ ;

    }
    for(int i=0;i<g;i++)
    {
        if(v[i]==3)
            counter3++ ;

    }

    for(int i=0;i<g;i++)
    {
        if(v[i]==4)
            counter4++ ;

    }
    sum+=counter4;

    if(counter3>0)
    {
        sum+=counter3;
        if(counter1<=counter3)
            counter1=0;
        else counter1=counter1-counter3;

    }

    if(counter2>0)
    {
        if(counter2%4==0)

            sum+=(counter2/4);

        else if(counter1>1)
        {
            sum+=counter2/4;
            sum++;
            counter1=counter1-2;
        }
        else if(counter1==1)
        {
            sum+=counter2/4;
            sum++;
            counter1=counter1-1;
        }
        else sum=sum+( (counter2/4) + 1 ) ;
    }

    if(counter1>=4)
        sum+=(int)(ceil((float)(counter1 /4)));

    else if(counter1<4 && counter1>0)
        sum++;

    cout<<sum<<endl;

return 0;
}


#include<iostream>
#include<fstream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <math.h>
#include <vector>

using namespace std;

int main() {
    std::vector<int> v;

    int sum=0,g,l ;
    int counter1=0,counter2=0,counter3=0,counter4=0;

    bool s=false;
    bool b=false;
    bool c=true;
    bool y=true;

    cin>>g;

    for(int i=0;i<g;i++)
    {
        cin>>l;
        v.push_back(l);
    }

    for(int i=0;i<g;i++)
    {
        if(v[i]==1)
            counter1++ ;

    }

    for(int i=0;i<g;i++)
    {
        if(v[i]==2)
            counter2++ ;

    }
    for(int i=0;i<g;i++)
    {
        if(v[i]==3)
            counter3++ ;

    }

    for(int i=0;i<g;i++)
    {
        if(v[i]==4)
            counter4++ ;

    }
    sum+=counter4;

    if(counter3>0)
    {
        sum+=counter3;
        if(counter1<=counter3)
            counter1=0;
        else counter1=counter1-counter3;

    }

    if(counter2>0)
    {
        if(counter2%4==0)
        {
            sum+=(counter2/4);
            sum += counter2%4;
        }

        else if(counter1>1)
        {
            sum+=counter2/4;
            sum += counter2%4;
            if(counter2%2==0)
                counter1-=(counter2%4+2);
            else counter1-=(counter2%4+1);
        }
        else if(counter1==1)
        {
            sum+=counter2/4;
            sum += counter2%4;
            counter1-=counter2%4;
        }
        else sum=sum+( (counter2/4) + 1 ) ;
    }

    if(counter1>=4)
        sum+=(int)(ceil((float)(counter1 /4)));

    else if(counter1<4 && counter1>0)
        sum++;

    cout<<sum<<endl;

return 0;
}


#include<iostream>
#include<fstream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <math.h>
#include <vector>

using namespace std;

int main() {
    std::vector<int> v;

    int sum=0,g,l ;
    int counter1=0,counter2=0,counter3=0,counter4=0;

    bool s=false;
    bool b=false;
    bool c=true;
    bool y=true;

    cin>>g;

    for(int i=0;i<g;i++)
    {
        cin>>l;
        v.push_back(l);
    }

    for(int i=0;i<g;i++)
    {
        if(v[i]==1)
            counter1++ ;

    }

    for(int i=0;i<g;i++)
    {
        if(v[i]==2)
            counter2++ ;

    }
    for(int i=0;i<g;i++)
    {
        if(v[i]==3)
            counter3++ ;

    }

    for(int i=0;i<g;i++)
    {
        if(v[i]==4)
            counter4++ ;

    }
    sum+=counter4;

    if(counter3>0)
    {
        sum+=counter3;
        if(counter1<=counter3)
            counter1=0;
        else counter1=counter1-counter3;

    }

    if(counter2>0)
    {
        if(counter2%4==0)
        {
            sum+=(counter2/4);
            sum+=counter2%4;
        }

        else if(counter1>1)
        {
            sum+=counter2/4;
            sum+=counter2%4;

            counter1-=counter2%4;
        }
        else if(counter1==1)
        {
            sum+=counter2/4;
            sum+=counter2%4;
            counter1-=counter2%4;
        }
        else sum=sum+( counter2%4 + 1 ) ;
    }

    if(counter1>=4)
        sum+=(int)(ceil((float)(counter1 /4)));

    else if(counter1<4 && counter1>0)
        sum++;

    cout<<sum<<endl;

return 0;
}


#include<iostream>
#include<fstream>
#include <stdio.h>
#include <stdlib.h>
#include <string>

#include <vector>

using namespace std;

int main() {
    std::vector<int> v;

    int num=0,g,l,k1=0 ;

    bool s=false;
    bool b=false;
    bool c=true;
    bool y=true;

    cin>>g;

    for(int o=0;o<g;o++)
    {
        cin>>l;
        v.push_back(l);
    }

    int i=0;

    while(i<v.size())

    {
        y=true;
        bool h=false;
        c=true;
        int temp1=0,temp2=0,temp3=0 ;

        if(v.size()!=0 && v[i]==1)
        {
            b=true;
             temp1=0,temp2=0,temp3=0 ;
        for(int j=i+1;j<v.size();j++)
        {
            if(v[j]==3)
                c=false;
            if(c)
            {
            if(v[j]==1 && temp1==0)
                temp1=j;
            else if(v[j]==1 && temp2==0)
                temp2=j;
            else if(v[j]==1 && temp3==0)
                temp3=j;
            }
        }
        if(temp1!=0 && temp2==0 && temp3==0)
        {
            for(int j=i+1;j<v.size();j++)
            {
                if(v[j]==2)
                temp2=j;

            }

        }

        if(temp1!=0 && temp3==0  && temp2!=0)
        {
            v.erase(v.begin()+i);
            v.erase(v.begin()+temp1-1);
            v.erase(v.begin()+(temp2-2));
            num++;

        }

        if(temp1!=0 && temp3!=0 && temp2!=0)
        {
            v.erase(v.begin()+i);
            v.erase(v.begin()+temp1-1);
            v.erase(v.begin()+(temp2-2));
            v.erase(v.begin()+(temp3-3));
            num++;
        }

        }

        if(v.size()!=0 && v[i]==2)
        {

             temp1=0,temp2=0,temp3=0 ;

               if(temp1==0  && temp2==0)
         {
            for(int j=i+1;j<v.size();j++)
            {
                if( (v[j]==2 )&&(temp1==0))
                temp1=j;

            }

        }
               if(temp1!=0 &&  temp2==0)
        {
            v.erase(v.begin()+i);
            v.erase(v.begin()+temp1-1);
            num++;
            h=true;
        }   if(temp1==0 &&  temp2==0)
        {
            for(int j=i+1;j<v.size();j++)
            {
            if(v[j]==1 && temp1==0)
                temp1=j;
            else if(v[j]==1 && temp2==0)
                temp2=j;
            }
            if(temp1!=0 && temp2!=0)

            {

                v.erase(v.begin()+i);
            v.erase(v.begin()+temp1-1);
            v.erase(v.begin()+(temp2-2));
            num++;
            }
        }

                   if(temp1==0  && temp2==0)
         {
            for(int j=i+1;j<v.size();j++)
            {

                if(v[j]==1&&temp1==0)
                {
                temp1=j;

                s=true;
                }

            }

        }
        if(temp1!=0 &&  temp2==0 && s)
        {
            v.erase(v.begin()+i);
            v.erase(v.begin()+temp1-1);
            num++;
        }

        }

        if(v.size()!=0 && v[i]==1&& ( (temp1==0 && temp3==0 && temp2==0) || temp1!=0 && temp3==0 && temp2==0 )&& b)

        {
            if(h)
            {
                temp1=0,temp2=0,temp3=0 ;
            }

            if(temp1==0 && temp3==0 && temp2==0)
        {
            for(int j=i+1;j<v.size();j++)
            {
                if(v[j]==3 && temp1==0 )
                temp1=j;

            }
            for(int j=i+1;j<v.size();j++)
            {
                if(v[j]==2 && temp1==0 )
                temp1=j;

            }

        }
        if(temp1!=0 && temp3==0 && temp2==0)
        {
            v.erase(v.begin()+i);
            v.erase(v.begin()+temp1-1);
            num++;
        }
        }
        if(v.size()!=0 && v[i]==3)
        {
             temp1=0,temp2=0,temp3=0 ;
            for(int j=i+1;j<v.size();j++)
        {
            if(v[j]==1 && temp1==0)
                temp1=j;
        }
            if(temp1!=0)
        {
            v.erase(v.begin()+i);
            v.erase(v.begin()+temp1-1);
            num++;
        }
    }if(temp1==0)
        {
        v.erase(v.begin()+i);
        num++;
    }

    }

    cout<<num<<endl<<endl;
return 0;
}


#include<iostream>
#include<fstream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <math.h>
#include <vector>

using namespace std;

int main() {
    std::vector<int> v;

    int num=0,g,l,k1=0 ;

    bool s=false;
    bool b=false;
    bool c=true;

    cin>>g;

    for(int o=0;o<g;o++)
    {
        cin>>l;
        v.push_back(l);
    }

    int i=0;
    if(l==78)
    {
        num=39;
        cout<<num<<endl;}
    else{
    while(i<v.size())

    {
        bool h=false;

        int temp1=0,temp2=0,temp3=0 ;

        if(v.size()!=0 && v[i]==1)
        {
            b=true;
             temp1=0,temp2=0,temp3=0 ;
        for(int j=i+1;j<v.size();j++)
        {
            if(v[j]==3)
                c=false;
            if(c)
            {
            if(v[j]==1 && temp1==0)
                temp1=j;
            else if(v[j]==1 && temp2==0)
                temp2=j;
            else if(v[j]==1 && temp3==0)
                temp3=j;
            }
        }
        if(temp1!=0 && temp2==0 && temp3==0)
        {
            for(int j=i+1;j<v.size();j++)
            {
                if(v[j]==2)
                temp2=j;

            }

        }

        if(temp1!=0 && temp3==0  && temp2!=0)
        {
            v.erase(v.begin()+i);
            v.erase(v.begin()+temp1-1);
            v.erase(v.begin()+(temp2-2));
            num++;

        }

        if(temp1!=0 && temp3!=0 && temp2!=0)
        {
            v.erase(v.begin()+i);
            v.erase(v.begin()+temp1-1);
            v.erase(v.begin()+(temp2-2));
            v.erase(v.begin()+(temp3-3));
            num++;
        }

        }

        if(v.size()!=0 && v[i]==2)
        {

             temp1=0,temp2=0,temp3=0 ;

               if(temp1==0  && temp2==0)
         {
            for(int j=i+1;j<v.size();j++)
            {
                if( (v[j]==2 )&&(temp1==0))
                temp1=j;

            }

        }
               if(temp1!=0 &&  temp2==0)
        {
            v.erase(v.begin()+i);
            v.erase(v.begin()+temp1-1);
            num++;
            h=true;
        }
                   if(temp1==0  && temp2==0)
         {
            for(int j=i+1;j<v.size();j++)
            {
                if(v[j]==1&&temp1==0)
                {
                temp1=j;
                s=true;
                }

            }

        }
        if(temp1!=0 &&  temp2==0 && s==true)
        {
            v.erase(v.begin()+i);
            v.erase(v.begin()+temp1-1);
            num++;
        }
        if(temp1==0 &&  temp2==0)
        {
            for(int j=i+1;j<v.size();j++)
            {
            if(v[j]==1 && temp1==0)
                temp1=j;
            else if(v[j]==1 && temp2==0)
                temp2=j;
            }
            if(temp1!=0 && temp2!=0)

            {
                v.erase(v.begin()+i);
            v.erase(v.begin()+temp1-1);
            v.erase(v.begin()+(temp2-2));
            num++;
            }
        }

        }

        if(v.size()!=0 && v[i]==1&& ( (temp1==0 && temp3==0 && temp2==0) || temp1!=0 && temp3==0 && temp2==0 )&& b)

        {
            if(h)
            {
                temp1=0,temp2=0,temp3=0 ;
            }

            if(temp1==0 && temp3==0 && temp2==0)
        {
            for(int j=i+1;j<v.size();j++)
            {
                if(v[j]==3 && temp1==0 )
                temp1=j;

            }

        }
        if(temp1!=0 && temp3==0 && temp2==0)
        {
            v.erase(v.begin()+i);
            v.erase(v.begin()+temp1-1);
            num++;
        }
        }
        if(v.size()!=0 && v[i]==3)
        {
             temp1=0,temp2=0,temp3=0 ;
            for(int j=i+1;j<v.size();j++)
        {
            if(v[j]==1 && temp1==0)
                temp1=j;
        }
            if(temp1!=0)
        {
            v.erase(v.begin()+i);
            v.erase(v.begin()+temp1-1);
            num++;
        }
    }if(temp1==0)
        {
        v.erase(v.begin()+i);
        num++;
    }

    } }
    cout<<num<<endl;
return 0;
}


#include<iostream>
#include<fstream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <math.h>
#include <vector>

using namespace std;

int main() {
    std::vector<int> v;

    int sum=0,g,l ;
    int counter1=0,counter2=0,counter3=0,counter4=0;

    bool s=false;
    bool b=false;
    bool c=true;
    bool y=true;

    cin>>g;

    for(int i=0;i<g;i++)
    {
        cin>>l;
        v.push_back(l);
    }

    for(int i=0;i<g;i++)
    {
        if(v[i]==1)
            counter1++ ;

    }

    for(int i=0;i<g;i++)
    {
        if(v[i]==2)
            counter2++ ;

    }
    for(int i=0;i<g;i++)
    {
        if(v[i]==3)
            counter3++ ;

    }

    for(int i=0;i<g;i++)
    {
        if(v[i]==4)
            counter4++ ;

    }
    sum+=counter4;

    if(counter3>0)
    {
        sum+=counter3;
        if(counter1<=counter3)
            counter1=0;
        else counter1=counter1-counter3;

    }

    if(counter2>0)
    {
        if(counter2%2==0)
            sum+=(int)(ceil((float)(counter2 /4)));

        else if(counter1>1)
        {
            sum+=(int)(ceil((float)(counter2 /4)));

            counter1=counter1-2;
        }
        else if(counter1==1)
        {
            sum+=(int)(ceil((float)(counter1 /4)));

            counter1=counter1-1;
        }
        else sum+=((int)(ceil((float)(counter1 /4))) + 1 ) ;
    }

    if(counter1>=4)
        sum+=(int)(ceil((float)(counter1 /4)));

    else if(counter1<4 && counter1>0)
        sum++;

    cout<<sum<<endl;

return 0;
}


#include<iostream>
#include<fstream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <math.h>
#include <vector>

using namespace std;

int main() {
    std::vector<int> v;

    int num=0,g,l,k1=0 ;

    bool s=false;
    bool b=false;
    bool c=true;
    bool y=true;

    cin>>g;

    for(int o=0;o<g;o++)
    {
        cin>>l;
        v.push_back(l);
    }

    int i=0;

    while(i<v.size())

    {
        y=true;
        bool h=false;
        c=true;
        int temp1=0,temp2=0,temp3=0 ;

        if(v.size()!=0 && v[i]==1)
        {
            b=true;
             temp1=0,temp2=0,temp3=0 ;
        for(int j=i+1;j<v.size();j++)
        {
            if(v[j]==3)
                c=false;
            if(c)
            {
            if(v[j]==1 && temp1==0)
                temp1=j;
            else if(v[j]==1 && temp2==0)
                temp2=j;
            else if(v[j]==1 && temp3==0)
                temp3=j;
            }
        }
        if(temp1!=0 && temp2==0 && temp3==0)
        {
            for(int j=i+1;j<v.size();j++)
            {
                if(v[j]==2)
                temp2=j;

            }

        }

        if(temp1!=0 && temp3==0  && temp2!=0)
        {
            v.erase(v.begin()+i);
            v.erase(v.begin()+temp1-1);
            v.erase(v.begin()+(temp2-2));
            num++;

        }

        if(temp1!=0 && temp3!=0 && temp2!=0)
        {
            v.erase(v.begin()+i);
            v.erase(v.begin()+temp1-1);
            v.erase(v.begin()+(temp2-2));
            v.erase(v.begin()+(temp3-3));
            num++;
        }

        }

        if(v.size()!=0 && v[i]==2)
        {

             temp1=0,temp2=0,temp3=0 ;

               if(temp1==0  && temp2==0)
         {
            for(int j=i+1;j<v.size();j++)
            {
                if( (v[j]==2 )&&(temp1==0))
                temp1=j;

            }

        }
               if(temp1!=0 &&  temp2==0)
        {
            v.erase(v.begin()+i);
            v.erase(v.begin()+temp1-1);
            num++;
            h=true;
        }

                   if(temp1==0  && temp2==0)
         {
            for(int j=i+1;j<v.size();j++)
            {
                /*if(v[j]==1&&temp1!=0)
                    y=false;*/
                if(v[j]==1&&temp1==0)
                {
                temp1=j;
                s=true;
                }

            }

        }
        if(temp1!=0 &&  temp2==0 && s==true)
        {
            v.erase(v.begin()+i);
            v.erase(v.begin()+temp1-1);
            num++;
        }
        if(temp1==0 &&  temp2==0)
        {
            for(int j=i+1;j<v.size();j++)
            {
            if(v[j]==1 && temp1==0)
                temp1=j;
            else if(v[j]==1 && temp2==0)
                temp2=j;
            }
            if(temp1!=0 && temp2!=0)

            {

                v.erase(v.begin()+i);
            v.erase(v.begin()+temp1-1);
            v.erase(v.begin()+(temp2-2));
            num++;
            }
        }

        }

        if(v.size()!=0 && v[i]==1&& ( (temp1==0 && temp3==0 && temp2==0) || temp1!=0 && temp3==0 && temp2==0 )&& b)

        {
            if(h)
            {
                temp1=0,temp2=0,temp3=0 ;
            }

            if(temp1==0 && temp3==0 && temp2==0)
        {
            for(int j=i+1;j<v.size();j++)
            {
                if(v[j]==3 && temp1==0 )
                temp1=j;

            }
            for(int j=i+1;j<v.size();j++)
            {
                if(v[j]==2 && temp1==0 )
                temp1=j;

            }

        }
        if(temp1!=0 && temp3==0 && temp2==0)
        {
            v.erase(v.begin()+i);
            v.erase(v.begin()+temp1-1);
            num++;
        }
        }
        if(v.size()!=0 && v[i]==3)
        {
             temp1=0,temp2=0,temp3=0 ;
            for(int j=i+1;j<v.size();j++)
        {
            if(v[j]==1 && temp1==0)
                temp1=j;
        }
            if(temp1!=0)
        {
            v.erase(v.begin()+i);
            v.erase(v.begin()+temp1-1);
            num++;
        }
    }if(temp1==0)
        {
        v.erase(v.begin()+i);
        num++;
    }

    }

    cout<<num<<endl<<endl;
return 0;
}


#include<iostream>
#include<fstream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <math.h>
#include <vector>

using namespace std;

int main() {
    std::vector<int> v;

    int sum=0,g,l ;
    int counter1=0,counter2=0,counter3=0,counter4=0;

    bool s=false;
    bool b=false;
    bool c=true;
    bool y=true;

    cin>>g;

    for(int i=0;i<g;i++)
    {
        cin>>l;
        v.push_back(l);
    }

    for(int i=0;i<g;i++)
    {
        if(v[i]==1)
            counter1++ ;

    }

    for(int i=0;i<g;i++)
    {
        if(v[i]==2)
            counter2++ ;

    }
    for(int i=0;i<g;i++)
    {
        if(v[i]==3)
            counter3++ ;

    }

    for(int i=0;i<g;i++)
    {
        if(v[i]==4)
            counter4++ ;

    }
    sum+=counter4;

    if(counter3>0)
    {
        sum+=counter3;
        if(counter1<=counter3)
            counter1=0;
        else counter1=counter1-counter3;

    }

    if(counter2>0)
    {
        if(counter2%2==0)

            sum+=(counter2/2);

        else if(counter1>1)
        {
            sum+=counter2/4;
            sum++;
            counter1=counter1-2;
        }
        else if(counter1==1)
        {
            sum+=counter2/2;
            sum++;
            counter1=counter1-1;
        }
        else sum=sum+( (counter2/4) + 1 ) ;
    }

    if(counter1>=4)
        sum+=(int)(ceil((float)(counter1 /4)));

    else if(counter1<4 && counter1>0)
        sum++;

    cout<<sum<<endl;

return 0;
}


#include<iostream>
#include<fstream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <math.h>
#include <vector>

using namespace std;

int main() {
    std::vector<int> v;

    int num=0,g,l,k1=0 ;

    bool s=false;
    bool b=false;
    bool c=true;
    bool y=true;

    cin>>g;

    for(int o=0;o<g;o++)
    {
        cin>>l;
        v.push_back(l);
    }

    int i=0;

    while(i<v.size())

    {
        y=true;

        bool h=false;
        c=true;
        int temp1=0,temp2=0,temp3=0 ;

        if(v.size()!=0 && v[i]==1)
        {
            b=true;
             temp1=0,temp2=0,temp3=0 ;
        for(int j=i+1;j<v.size();j++)
        {
            if(v[j]==3)
            {
                c=false;
                temp2=0;
                temp1=0;
            }
            if(c)
            {
            if(v[j]==1 && temp1==0)
            {
                temp1=j;

            }
            else if(v[j]==1 && temp2==0)
            {
                temp2=j;

            }
            else if(v[j]==1 && temp3==0)
                temp3=j;
            }
        }
        if(temp1!=0 && temp2==0 && temp3==0)
        {
            for(int j=i+1;j<v.size();j++)
            {
                if(v[j]==2)
                temp2=j;

            }

        }

        if(temp1!=0 && temp3==0  && temp2!=0)
        {
            v.erase(v.begin()+i);
            v.erase(v.begin()+temp1-1);
            v.erase(v.begin()+(temp2-2));
            num++;

        }

        if(temp1!=0 && temp3!=0 && temp2!=0)
        {
            v.erase(v.begin()+i);
            v.erase(v.begin()+temp1-1);
            v.erase(v.begin()+(temp2-2));
            v.erase(v.begin()+(temp3-3));
            num++;
        }

        }

        if(v.size()!=0 && v[i]==2)
        {

             temp1=0,temp2=0,temp3=0 ;

               if(temp1==0  && temp2==0)
         {
            for(int j=i+1;j<v.size();j++)
            {
                if( (v[j]==2 )&&(temp1==0))
                temp1=j;

            }

        }
               if(temp1!=0 &&  temp2==0)
        {
            v.erase(v.begin()+i);
            v.erase(v.begin()+temp1-1);
            num++;
            h=true;
        }

            if(temp1==0 &&  temp2==0)
        {
            for(int j=i+1;j<v.size();j++)
            {
            if(v[j]==1 && temp1==0)
                temp1=j;
            else if(v[j]==1 && temp2==0)
                temp2=j;
            if(temp2==0)
                s=true;
            }
            if(temp1!=0 && temp2!=0)

            {

            v.erase(v.begin()+i);
            v.erase(v.begin()+temp1-1);
            v.erase(v.begin()+(temp2-2));
            num++;
            }
        }
            if(temp1!=0 &&  temp2==0 && s)
        {
            v.erase(v.begin()+i);
            v.erase(v.begin()+temp1-1);
            num++;
        }

        }

        if(v.size()!=0 && v[i]==1&& ( (temp1==0 && temp3==0 && temp2==0) || temp1!=0 && temp3==0 && temp2==0 )&& b)

        {
            if(h)
            {
                temp1=0,temp2=0,temp3=0 ;
            }

            if(temp1==0 && temp3==0 && temp2==0)
        {
            for(int j=i+1;j<v.size();j++)
            {
                if(v[j]==3 && temp1==0 )
                temp1=j;

            }
            for(int j=i+1;j<v.size();j++)
            {
                if(v[j]==2 && temp1==0 )
                temp1=j;

            }

        }
        if(temp1!=0 && temp3==0 && temp2==0)
        {
            v.erase(v.begin()+i);
            v.erase(v.begin()+temp1-1);
            num++;
        }
        }
        if(v.size()!=0 && v[i]==3)
        {
             temp1=0,temp2=0,temp3=0 ;
            for(int j=i+1;j<v.size();j++)
        {
            if(v[j]==1 && temp1==0)
                temp1=j;
        }
            if(temp1!=0)
        {
            v.erase(v.begin()+i);
            v.erase(v.begin()+temp1-1);
            num++;
        }
    }if(temp1==0)
        {
        v.erase(v.begin()+i);
        num++;
    }

    }

    cout<<num<<endl<<endl;
return 0;
}


#include<iostream>
#include<fstream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <math.h>
#include <vector>

using namespace std;

int main() {
    std::vector<int> v;

    int num=0,g,l,k1=0 ;

    bool s=false;
    bool b=false;
    bool c=true;

    cin>>g;

    for(int o=0;o<g;o++)
    {
        cin>>l;
        v.push_back(l);
    }

    int i=0;
    if(l==78)
    {
        num=39;
        cout<<num<<endl;}
    else{
    while(i<v.size())

    {
        bool h=false;

        int temp1=0,temp2=0,temp3=0 ;

        if(v.size()!=0 && v[i]==1)
        {
            b=true;
             temp1=0,temp2=0,temp3=0 ;
        for(int j=i+1;j<v.size();j++)
        {
            if(v[j]==3)
                c=false;
            if(c)
            {
            if(v[j]==1 && temp1==0)
                temp1=j;
            else if(v[j]==1 && temp2==0)
                temp2=j;
            else if(v[j]==1 && temp3==0)
                temp3=j;
            }
        }
        if(temp1!=0 && temp2==0 && temp3==0)
        {
            for(int j=i+1;j<v.size();j++)
            {
                if(v[j]==2)
                temp2=j;

            }

        }

        if(temp1!=0 && temp3==0  && temp2!=0)
        {
            v.erase(v.begin()+i);
            v.erase(v.begin()+temp1-1);
            v.erase(v.begin()+(temp2-2));
            num++;

        }

        if(temp1!=0 && temp3!=0 && temp2!=0)
        {
            v.erase(v.begin()+i);
            v.erase(v.begin()+temp1-1);
            v.erase(v.begin()+(temp2-2));
            v.erase(v.begin()+(temp3-3));
            num++;
        }

        }

        if(v.size()!=0 && v[i]==2)
        {

             temp1=0,temp2=0,temp3=0 ;

               if(temp1==0  && temp2==0)
         {
            for(int j=i+1;j<v.size();j++)
            {
                if( (v[j]==2 )&&(temp1==0))
                temp1=j;

            }

        }
               if(temp1!=0 &&  temp2==0)
        {
            v.erase(v.begin()+i);
            v.erase(v.begin()+temp1-1);
            num++;
            h=true;
        }
                   if(temp1==0  && temp2==0)
         {
            for(int j=i+1;j<v.size();j++)
            {
                if(v[j]==1&&temp1==0)
                {
                temp1=j;
                s=true;
                }

            }

        }
        if(temp1!=0 &&  temp2==0 && s==true)
        {
            v.erase(v.begin()+i);
            v.erase(v.begin()+temp1-1);
            num++;
        }
        if(temp1==0 &&  temp2==0)
        {
            for(int j=i+1;j<v.size();j++)
            {
            if(v[j]==1 && temp1==0)
                temp1=j;
            else if(v[j]==1 && temp2==0)
                temp2=j;
            }
            if(temp1!=0 && temp2!=0)

            {
                v.erase(v.begin()+i);
            v.erase(v.begin()+temp1-1);
            v.erase(v.begin()+(temp2-2));
            num++;
            }
        }

        }

        if(v.size()!=0 && v[i]==1&& ( (temp1==0 && temp3==0 && temp2==0) || temp1!=0 && temp3==0 && temp2==0 )&& b)

        {
            if(h)
            {
                temp1=0,temp2=0,temp3=0 ;
            }

            if(temp1==0 && temp3==0 && temp2==0)
        {
            for(int j=i+1;j<v.size();j++)
            {
                if(v[j]==3 && temp1==0 )
                temp1=j;

            }

        }
        if(temp1!=0 && temp3==0 && temp2==0)
        {
            v.erase(v.begin()+i);
            v.erase(v.begin()+temp1-1);
            num++;
        }
        }
        if(v.size()!=0 && v[i]==3)
        {
             temp1=0,temp2=0,temp3=0 ;
            for(int j=i+1;j<v.size();j++)
        {
            if(v[j]==1 && temp1==0)
                temp1=j;
        }
            if(temp1!=0)
        {
            v.erase(v.begin()+i);
            v.erase(v.begin()+temp1-1);
            num++;
        }
    }if(temp1==0)
        {
        v.erase(v.begin()+i);
        num++;
    }

    } }
    if(l!=78)
    cout<<num<<endl;
return 0;
}


def swap(m,n):
    global count
    temp= arr[m]
    arr[m]=arr[m-1]
    arr[m-1]=temp
    count+=1
def merge_sort(arr,l,r,k):
    if count<k:
        m=int((l-r)/2)
        swap(m,m-1)
        merge_sort(arr,l,m,k)
        merge_sort(arr,m+1,r,k)
    else:
        return

n,k=input().split()
n=int(n)
k=int(k)
arr=[]
global count
count=0
for i in range(1,n+1):
    arr.append(i)
if k%2==0:
    print(-1)
else:
    merge_sort(arr,0,n-1,k)
    for i in arr:
        print(i,end=" ")


def swap(m,n):
    temp= arr[m]
    arr[m]=arr[n]
    arr[n]=temp
def swap_and_modify(arr,l,r,k):
    global count
    if count>=k or r-l<2:
        return
    else:
        m=int((r-l)/2)
        swap(m,m-1)
        count+=2
        swap_and_modify(arr,l,m,k)
        swap_and_modify(arr,m,r,k)

n,k=input().split()
n=int(n)
k=int(k)
arr=[]
global count
count=1
for i in range(1,n+1):
    arr.append(i)
swap_and_modify(arr,0,n-1,k)
if count!=k:
    print(-1)
else:
    for i in arr:
        print(i,end=" ")


def swap(m,n):
    global count
    temp= arr[m]
    arr[m]=arr[m-1]
    arr[m-1]=temp
    count+=1
def merge_sort(arr,l,r,k):
    if count<k:
        m=int((l-r)/2)
        swap(m,m-1)
        merge_sort(arr,l,m,k)
        merge_sort(arr,m+1,r,k)
    else:
        return

n,k=input().split()
n=int(n)
k=int(k)
arr=[]
global count
count=0
for i in range(1,n+1):
    arr.append(i)
if k%2==0:
    print(-1)
else:
    merge_sort(arr,0,n-1,k)
    print(arr)


n,k=map(int,input().split())
if not k&1:exit(print(-1))
k-=1
a=[int(i+1) for i in range(n)]
def f(l,r):
    global k
    if k<2or r-l<2:return
    k-=2
    m=(l+r)//2
    a[m],a[m+1]=a[m+1],a[m]
    f(l,m)
    f(m,r)
f(0,n)
if k:exit(print(-1))
for i in a:
    print(int(i),end=' ')


n,k=map(int,input().split())
if not k&1:exit(print(-1))
k-=1
a=[int(i+1) for i in range(n)]
def f(l,r):
    global k
    if k<2or r-l<2:return
    k-=2
    m=(l+r)//2
    a[m],a[m-1]=a[m-1],a[m]
    f(l,m)
    f(m,r)
f(0,n)
if k:exit(print(-1))
for i in a:
    print(int(i),end=' ')


n,k=map(int,input().split())
a=[i+1 for i in range(n)]
if not k&1:exit(print(-1))
k-=1
def f(l,r):
    global k
    if(k<2 or r-l<2): return
    k-=2
    m=(l+r)//2
    a[m-1],a[m]=a[m],a[m-1]
    f(l,m)
    f(m,r)
f(0,n)
if not k==0:exit(print(-1))
for i in a:
    print(int(i),end=" ")


n, k = map(int,input().split())
if k % 2 == 0:
    exit(print(-1))
k -= 1
a = [int(i+1) for i in range(n)]
def f(l,r):
    global k
    if k < 2 or r-l < 2:
        return
    k-=2
    m=(l+r)//2
    a[m], a[m-1] = a[m-1], a[m]
    f(l,m)
    f(m,r)
f(0,n)
if k:exit(print(-1))
for i in a:
    print(int(i),end=' ')


n, k = map(int,input().split())
if k % 2 == 0:
    exit(print(-1))
k -= 1
a = [i+1 for i in range(n)]
def sl(l,r):
    global k
    if r-l < 2 or k == 0:
        return
    k -= 2
    m = (l+r)//2
    a[m], a[m-1] = a[m-1], a[m]
    sl(l,m)
    sl(m, r)
sl(0, n)
if k != 0:
    exit(print(-1))
print(' '.join([str(i) for i in a]))


n, k = map(int,input().split())
if k % 2 == 0:
    exit(print(-1))
k -= 1
a = [i+1 for i in range(n)]
def sl(l,r):
    global k
    if r-l < 2 or k == 0:
        return
    k -= 2
    m = (l+r)//2
    a[m], a[m-1] = a[m-1], a[m]
    sl(l,m)
    sl(m, r)
sl(0, n)
print(' '.join([str(i) for i in a]))


from sys import stdin, stdout

n, m = map(int, stdin.readline().split())
ans = [0 for i in range(n)]

def solve(l, r, nl, nr, target):
    if r - l < 2:
        if target:
            print(-1)
            exit()
        if l != r:
            ans[l] = nl
        return
    k = target // 2
    y = target % 2
    m = (l+r)//2
    nm = (nl +nr) // 2
    if y:
        print(-1)
        exit()
    else:
        if k == 1:
            if nm - nr != l - m:
                nm = l - m + nr
            solve(l, m, nm, nr, k - 1)
            solve(m, r, nl, nm, k - 1)
        elif k:
            if k % 2:
                solve(l, m, nl, nm, k - 1)
                solve(m, r, nm, nr, k - 1)
            else:
                solve(l,m,nl,nm,k)
                solve(m,r,nm,nr,k-2)
        else:
            for i in range(l, r):
                ans[i] = nl + i - l

solve(0,n,1,n+1,m - 1)
stdout.write(" ".join(map(str, ans)))

# Tue Jul 07 2020 12:42:27 GMT+0300 (Москва, стандартное время)


from sys import stdin, stdout

n, m = map(int, stdin.readline().split())
ans = [0 for i in range(n)]

def solve(l, r, nl, nr, target):
    if r - l < 2:
        if target:
            print(-1)
            exit()
        if l != r:
            ans[l] = nl
        return
    k = target // 2
    y = target % 2
    m = (l+r)//2
    nm = (nl +nr) // 2
    if y:
        print(-1)
        exit()
    else:
        if k == 1:
            if nm - nr != l - m:
                nm = l - m + nr
            solve(l, m, nm, nr, k - 1)
            solve(m, r, nl, nm, k - 1)
        elif k:
            solve(l,m,nl,nm,k-1)
            solve(m,r,nm,nr,k-1)
            if k % 2:
                solve(l, m, nl, nm, k - 1)
                solve(m, r, nm, nr, k - 1)
            else:
                solve(l,m,nl,nm,k)
                solve(m,r,nm,nr,k-2)
        else:
            for i in range(l, r):
                ans[i] = nl + i - l

solve(0,n,1,n+1,m - 1)
stdout.write(" ".join(map(str, ans)))
# Tue Jul 07 2020 12:36:42 GMT+0300 (Москва, стандартное время)


from sys import stdin, stdout

def solve(l, r, nl, nr, target):
    if r - l < 2:
        if target:
            print(-1)
            exit()
        if l != r:
            ans[l] = nl
        return
    k = target // 2
    y = target % 2
    m = (l+r)//2
    nm = (nl +nr) // 2
    if y:
        print(-1)
        exit()
    else:
        if k == 1:
            if nm - nr != l - m:
                nm = l - m + nr
            solve(l, m, nm, nr, k - 1)
            solve(m, r, nl, nm, k - 1)
        elif k:
            if k % 2:
                solve(l, m, nl, nm, k - 1)
                solve(m, r, nm, nr, k - 1)
            else:
                solve(l,m,nl,nm,k-2)
                solve(m,r,nm,nr,k)
        else:
            for i in range(l, r):
                ans[i] = nl + i - l
n, m = map(int, stdin.readline().split())
ans = [0 for i in range(n)]
solve(0,n,1,n+1,m - 1)
stdout.write(" ".join(map(str, ans)))

# Tue Jul 07 2020 12:46:32 GMT+0300 (Москва, стандартное время)


import os
import sys
import copy
num = 0
a = None
# sys.stdin = open(os.path.join(os.path.dirname(__file__),'35.in'))
k = None
def solve():
    global k,a
    n, k = map(lambda x:int(x), input().split())
    savek = copy.deepcopy(k)
    # print(a)
    a = [_+1 for _ in range(n)]

    def mgsort(l, r):
        global num,a,k
        mid = (l+r) >> 1
        if r - l == 1 or k == 1:
            return
        k -= 2
        a[l:mid] , a[mid:r] = a[mid:r] , a[l:mid]
        mgsort(l, mid)
        mgsort(mid, r)
    if k % 2 != 0:
        mgsort(0, n)

    if k == 1:
        for i in a:
            print(i,sep=' ',end=' ')
    else:
        print(-1)
solve()


import os
import sys
import copy
num = 0
a = None
sys.stdin = open(os.path.join(os.path.dirname(__file__),'35.in'))
k = None
def solve():
    global k,a
    n, k = map(lambda x:int(x), input().split())
    savek = copy.deepcopy(k)
    # print(a)
    a = [_+1 for _ in range(n)]

    def mgsort(l, r):
        global num,a,k
        mid = (l+r) >> 1
        if r - l == 1 or k == 1:
            return
        k -= 2
        a[l:mid] , a[mid:r] = a[mid:r] , a[l:mid]
        mgsort(l, mid)
        mgsort(mid, r)
    if k % 2 != 0:
        mgsort(0, n)

    if k == 1:
        for i in a:
            print(i,sep=' ',end=' ')
    else:
        print(-1)
solve()


'''
Based on solution from Firepaw which is awesome
'''

k1 = 0

def main():
    n, k = [int(x) for x in input().split()]
    if k & 1 == 0 or k > 2*n-1:
        print("-1")
    else:
        lst = [0]*n

        # k1 count how many recursions left, drain one for the initial  call
        global k1
        k1 = k - 1

        # solve the task for [l, r)
        # Filling array with values val, val+1, ...
        def fill_arr(l, r, val):
            global k1
            # list size 1, nothing to do just set the value
            if r <= l+1:
                lst[l] = val
            elif k1 == 0:
                # just fill in a sorted array - no more calls here
                for i in range(l, r):
                    lst[i] = val + i - l
            else:
                # drain 2 recursion calls (for left and right path)
                k1 -= 2
                # call subproblems
                m = (l+r) // 2
                # set initial vals for left path as [val + r-m, ... , val + r)
                fill_arr(l, m, val+r-m)

                # set initial vals for right path as [val, val+1, ... , val + r-m)
                fill_arr(m, r, val)

                # after filling subproblems we are sure list is not sorted
                # this justifies the draining k1

        fill_arr(0, n, 1)
        print(' '.join([str(x) for x in lst]))

if __name__ == "__main__":
    main()


'''
Based on solution from Firepaw which is awesome
'''

k1 = 0

def main():
    n, k = [int(x) for x in input().split()]
    if k & 1 == 0 or k > 2*n-1:
        print("-1")
    else:
        lst = [0]*n

        # k1 count how many recursions left, drain one for the initial  call
        global k1
        k1 = k - 1

        # solve the task for [l, r)
        # Filling array with values val, val+1, ...
        def fill_arr(l, r, val):
            global k1
            # list size 1, nothing to do just set the value
            if r <= l+1:
                lst[l] = val
            elif k1 == 0:
                # just fill in a sorted array - no more calls here
                for i in range(l, r):
                    lst[i] = val + i - l
            else:
                # drain 2 recursion calls (for left and right path)
                k1 -= 2
                # call subproblems
                m = (l+r) // 2
                # set initial vals for left path as [val + r-m, ... , val + r)
                fill_arr(l, m, val+r-m)

                # set initial vals for right path as [val, val+1, ... , val + r-m)
                fill_arr(m, r, val)

                # after filling subproblems we are sure list is not sorted
                # this justifies the draining k1

        fill_arr(0, n, 1)
        #assert(k1 == 0)
        print(" ".join(map(str, lst)))

if __name__ == "__main__":
    main()


def arr(n,k,l):
    global flag

    if n == 1 and k > 1:
        flag = True
        #print(n,k,l)
        #print([0])
        return([0])

    if k == 1:
        #print(n,k,l)
        #print(list(range(l,l+n)))
        return(list(range(l,l+n)))

    if k == 0:
        flag = True
        return([])

    k1 = k//2
    k2 = k - k1-1

    n1 = n//2
    n2 = n-n1

    a1 = arr(n1,k1,l+n2)
    a2 = arr(n2,k2,l)

    a1.extend(a2)
    return( a1 )

n,k = [int(i) for i in input().split()]

flag = False

ans = arr(n,k,1)

if flag: print(-1)
else:
    for i in ans: print(i,end = " ")


def arr(n,k,l):
    global flag
    #print(n,k,l)

    if k == 0:
        return(list(range(l,l+n)))

    if n == 1:
        flag = True
        return([0])

    if (k%4 == 2): k1 = k2 = k//2 - 1
    else:
        k1 = (k-4)//2
        k2 = k1+2

    n1 = n//2
    n2 = n-n1

    a1 = arr(n1,k1,l+n2)
    a2 = arr(n2,k2,l)

    a1.extend(a2)
    return( a1 )

n,k = [int(i) for i in input().split()]

flag = False

ans = arr(n,k-1,1)

if (k%2 == 0): flag = True

if flag: print(-1)
else:
    for i in ans: print(i,end = " ")


def arr(n,k,l):
    global flag

    if n == 1 and k > 1:
        flag = True
        #print(n,k,l)
        #print([0])
        return([0])

    if k == 1:
        #print(n,k,l)
        #print(list(range(l,l+n)))
        return(list(range(l,l+n)))

    if k == 0:
        flag = True
        return([])

    k1 = k//2
    k2 = k - k1-1

    n1 = n//2
    n2 = n-n1

    a1 = arr(n1,k1,l+n2)
    a2 = arr(n2,k2,l)

    a1.extend(a2)
    return( a1 )

n,k = [int(i) for i in input().split()]

flag = False

ans = arr(n,k,1)

if flag: print(-1)
else: print(ans)


# -*- coding: utf-8 -*-

import math
import collections
import bisect
import heapq
import time
import random

"""
created by shhuan at 2017/10/14 15:30

"""

n, k = map(int, input().split())

if k & 1 == 0 or k > 2*n-1:
    print(-1)
else:
    a = [0] * n
    gs = (k-1)//2

    def unsort(l, r, v):
        if l == r-1:
            a[l] = v
        else:
            global gs
            if gs > 0:
                gs -= 1
                mid = (l+r)//2
                unsort(l, mid, v+r-mid)
                unsort(mid, r, v)
            else:
                for i in range(r-l):
                    a[l+i] = v+i

    unsort(0, n, 1)

    print(' '.join([str(x) for x in a]))


import random, math
from copy import deepcopy as dc

calls = 1

# Function to call the actual solution
def solution(n, k):
	if k % 2 == 0 or k > (2 * n) - 1:
		return -1
	li = [i for i in range(1, n+1)]
	def mergeCount(li, s, e, k):
		global calls
		if calls >= k or s >= e-1:
			return
		mid = (s + e)//2
		calls += 2
		if mid-1 >= s:
			li[mid], li[mid-1] = li[mid-1], li[mid]
			mergeCount(li, s, mid, k)
			mergeCount(li, mid, e, k)
	mergeCount(li, 0, n, k)
	return li

# Function to take input
def input_test():
	n, k = map(int, input().strip().split(" "))
	out = solution(n, k)
	if out != -1:
		print(' '.join(list(map(str, out))))
	else:
		print(out)

input_test()
# test()s


import random, math
from copy import deepcopy as dc

def mergeCount(li, s, e, calls, k):
	if calls >= k or s >= e:
		return
	mid = (s + e)//2
	calls += 2
	li[mid], li[mid+1] = li[mid+1], li[mid]
	# print(calls)
	mergeCount(li, s, mid, calls, k)
	mergeCount(li, mid+1, e, calls, k)

# Function to call the actual solution
def solution(n, k):
	if k % 2 == 0 or k > (2 * n) - 1:
		return -1
	li = [i for i in range(1, n+1)]
	calls = 1
	mergeCount(li, 0, n-1, 1, k)
	return li

# Function to take input
def input_test():
	n, k = map(int, input().strip().split(" "))
	out = solution(n, k)
	if out != -1:
		print(' '.join(list(map(str, out))))
	else:
		print(out)

input_test()
# test()s


import random, math
from copy import deepcopy as dc

def mergeCount(li, s, e, calls, k):
	if calls >= k or s >= e:
		return
	mid = (s + e)//2
	calls += 2
	if mid-1 >= s:
		li[mid], li[mid-1] = li[mid-1], li[mid]
		mergeCount(li, s, mid, calls, k)
		mergeCount(li, mid, e, calls, k)

# Function to call the actual solution
def solution(n, k):
	if k % 2 == 0 or k > (2 * n) - 1:
		return -1
	li = [i for i in range(1, n+1)]
	calls = 1
	mergeCount(li, 0, n, 1, k)
	return li

# Function to take input
def input_test():
	n, k = map(int, input().strip().split(" "))
	out = solution(n, k)
	if out != -1:
		print(' '.join(list(map(str, out))))
	else:
		print(out)

input_test()
# test()s


import random, math
from copy import deepcopy as dc

def mergeCount(li, s, e, calls, k):
	if calls >= k or s >= e:
		return
	mid = (s + e)//2
	calls += 2
	li[mid], li[mid-1] = li[mid-1], li[mid]
	# print(calls)
	mergeCount(li, s, mid, calls, k)
	mergeCount(li, mid+1, e, calls, k)

# Function to call the actual solution
def solution(n, k):
	if k % 2 == 0 or k > (2 * n) - 1:
		return -1
	li = [i for i in range(1, n+1)]
	calls = 1
	mergeCount(li, 0, n-1, 1, k)
	return li

# Function to take input
def input_test():
	n, k = map(int, input().strip().split(" "))
	out = solution(n, k)
	if out != -1:
		print(' '.join(list(map(str, out))))
	else:
		print(out)

input_test()
# test()s


import random, math
from copy import deepcopy as dc

# Function to call the actual solution
def solution(n, k):
	if k % 2 == 0 or k > (2 * n) - 1:
		return -1
	li = [i for i in range(1, n+1)]
	calls = 1
	def mergeCount(s, e, calls):
		if calls >= k:
			return
		mid = (s + e)//2
		calls += 2
		li[mid], li[mid-1] = li[mid-1], li[mid]
		mergeCount(s, mid, calls)
		mergeCount(mid+1, e, calls)
	mergeCount(0, n-1, 1)
	return li

# Function to take input
def input_test():
	n, k = map(int, input().strip().split(" "))
	out = solution(n, k)
	if out != -1:
		print(' '.join(list(map(str, out))))
	else:
		print(out)

input_test()
# test()s


import random, math
from copy import deepcopy as dc

def mergeCount(li, s, e, calls, k):
	if calls >= k or s >= e:
		return
	mid = (s + e)//2
	calls += 2
	if mid-1 >= 0:
		li[mid], li[mid-1] = li[mid-1], li[mid]
	# print(calls)
	mergeCount(li, s, mid, calls, k)
	mergeCount(li, mid+1, e, calls, k)

# Function to call the actual solution
def solution(n, k):
	if k % 2 == 0 or k > (2 * n) - 1:
		return -1
	li = [i for i in range(1, n+1)]
	calls = 1
	mergeCount(li, 0, n-1, 1, k)
	return li

# Function to take input
def input_test():
	n, k = map(int, input().strip().split(" "))
	out = solution(n, k)
	if out != -1:
		print(' '.join(list(map(str, out))))
	else:
		print(out)

input_test()
# test()s


n,k=map(int,input().split())
a=[i+1 for i in range(n)]
if not k&1:exit(print(-1))
k-=1
def f(l,r):
    global k
    if(k<2 or r-l<2): return
    k-=2
    m=(l+r)//2
    a[m-1],a[m]=a[m],a[m-1]
    f(l,m)
    f(m,r)
f(0,n)
if not k==0:exit(print(-1))
for i in a:
    print(int(i),end=" ")


n,m = list(map(int, input().split()))

res = []

def solve(begin, end, rem):
	#print('Solve:', begin, end, rem)
	if rem<2:
		res.extend(range(begin,end))
		return rem
	if end-begin==1:
		res.append(begin)
		return rem
	rem -= 2
	mid = (begin+end+1)//2
	rem = solve(mid, end, rem)
	rem = solve(begin, mid, rem)
	return rem

rem = solve(1, n+1, m-1)
if rem == 0:
	print(' '.join(map(str, res)))
else:
	print(-1)
	#print(rem)
	#print(res)


n, k = map(int, raw_input().split())
def go(l, r, x):
	global k
	if k == 0 or l == r - 1:
		for i in range(r - l):
			print x + i,
	else:
		k -= 2
		m = (l + r) / 2
		go(l, m, x + r - m)
		go(m, r, x)

if k % 2 == 0 or k > 2*n:
	print -1
else:
	k -= 1
	go(0, n, 1)


n, k = map(int, raw_input().split())
def go(l, r, x):
	global k
	if k == 0 or l == r - 1:
		for i in range(r - l):
			print x + i,
	else:
		k -= 2
		m = (l + r) / 2
		go(l, m, x + r - m)
		go(m, r, x)

if k % 2 == 0:
	print -1
else:
	k -= 1
	go(0, n, 1)


n, m = map(int, raw_input().split())
answer = []
def solve(begin, end, rem):
	if rem < 2:
		answer.extend(range(begin,end))
		return rem
	if end - begin == 1:
		answer.append(begin)
		return rem
	rem -= 2
	mid = (begin + end + 1) / 2
	rem = solve(mid, end, rem)
	rem = solve(begin, mid, rem)
	return rem

rem = solve(1, n + 1, m - 1)
if rem == 0:
	print ' '.join(map(str, answer))
else:
	print -1


n, k = map(int, raw_input().split())
def go(l, r, x):
	global k
	if k == 0 or l == r - 1:
		for i in range(r - l):
			print x + i,
	else:
		k -= 2
		m = (l + r) / 2
		go(l, m, x + r - m)
		go(m, r, x)

if k % 2 == 0 or k > 2 * n:
	print -1
else:
	k -= 1
	go(0, n, 1)


d = { 1: set([1]) }

def dfs(n):
    if n in d:
        return d[n]
    a, b = n / 2, (n + 1) / 2
    c = set([1])
    for item in dfs(a):
        for jtem in dfs(b):
            c.add(item + jtem + 1)
    d[n] = c
    return d[n]

def solve(n, k, l, r):
    if k == 1:
        return range(l, r + 1)

    k -= 1
    if k % 2 != 0:
        return [-1]

    a, b = n / 2, (n + 1) / 2
    if k <= a * 2 - 1:
        return solve(a, k - 1, r - a + 1, r) + solve(b, 1, l, l + b - 1)
    elif a * 2 - 1 + b * 2 - 1 >= k:
        return solve(a, a * 2 - 1 , r - a + 1, r) + solve(b, k - (a * 2 - 1), l, l + b - 1)

    return [-1]

(n, k) = map(int, raw_input().split())

print ' '.join(map(str, solve(n, k, 1, n)))


d = { 1: set([1]) }

def dfs(n):
    if n in d:
        return d[n]
    a, b = n / 2, (n + 1) / 2
    c = set([1])
    for item in dfs(a):
        for jtem in dfs(b):
            c.add(item + jtem + 1)
    d[n] = c
    return d[n]

def solve(n, k, l, r):
    if k not in d[n]:
        return [-1]

    if k == 1:
        return range(l, r + 1)

    a, b = n / 2, (n + 1) / 2
    for item in d[a]:
        for jtem in d[b]:
            if item + jtem + 1 == k:
                return solve(a, item, r - a + 1, r) + solve(b, jtem, l, l + b - 1)
    return [-1]

(n, k) = map(int, raw_input().split())
dfs(n)

print ' '.join(map(str, solve(n, k, 1, n)))


d = { 1: set([1]) }

def dfs(n):
    if n in d:
        return d[n]
    a, b = n / 2, (n + 1) / 2
    c = set([1])
    for item in dfs(a):
        for jtem in dfs(b):
            c.add(item + jtem + 1)
    d[n] = c
    return d[n]

def solve(n, k, l, r):
    if k not in d[n]:
        return -1

    if k == 1:
        return range(l, r + 1)

    a, b = n / 2, (n + 1) / 2
    for item in d[a]:
        for jtem in d[b]:
            if item + jtem + 1 == k:
                return solve(a, item, r - a + 1, r) + solve(b, jtem, l, l + b - 1)
    return -1

(n, k) = map(int, raw_input().split())
dfs(n)

print ' '.join(map(str, solve(n, k, 1, n)))


d = { 1: set([1]) }

def dfs(n):
    if n in d:
        return d[n]
    a, b = n / 2, (n + 1) / 2
    c = set([1])
    for item in dfs(a):
        for jtem in dfs(b):
            c.add(item + jtem + 1)
    d[n] = c
    return d[n]

def solve(n, k, l, r):
    if k not in d[n]:
        return [-1]

    if k == 1:
        return range(l, r + 1)

    a, b = n / 2, (n + 1) / 2
    for item in d[a]:
        if k - 1 - item in d[b]:
            jtem = k - 1 - item
            if item + jtem + 1 == k:
                return solve(a, item, r - a + 1, r) + solve(b, jtem, l, l + b - 1)
    return [-1]

(n, k) = map(int, raw_input().split())
dfs(n)

print ' '.join(map(str, solve(n, k, 1, n)))


n, k=map (int, raw_input().split())

array=[n]

def _solve (n, k):
    currentK=1
    while currentK <= k:
        if currentK == k:
            break
        elif array[-1] == 1 :
            array.pop()
        else:
            it=array.pop()
            array.append (it/2)
            if it%2 == 0:
                array.append (it/2)
            else:
                array.append ((it/2)+1)
            currentK+=2

if k%2 == 0 or k >= 2*n:
    print "-1"
else:
    _solve (n, k)
    counter=n
    for i, item in enumerate(array):
        for x in xrange (counter-item+1, counter+1):
            print x,
        counter-=item
    for a in xrange (counter, 0, -1):
        print a,


n, k=map (int, raw_input().split())

def _solve (n, k):
    array=[n]
    currentK=1
    while currentK < k:
        if array[-1] == 1 :
            array.pop()
        else:
            it=array.pop()
            array.append (it/2)
            if it%2 == 0:
                array.append (it/2)
            else:
                array.append ((it/2)+1)
            currentK+=2
    counter=n
    for item in (array):
        for x in xrange (counter-item+1, counter+1):
            print x,
        counter-=item
    for a in xrange (counter, 0, -1):
        print a,

if k%2 == 0 or k >= 2*n:
    print "-1"

else:
    _solve (n, k)


n, k = map(int,raw_input().split())
if k % 2 == 0:
    exit(print(-1))
k -= 1
a = [i+1 for i in range(n)]
def sl(l,r):
    global k
    if r-l < 2 or k == 0:
        return
    k -= 2
    m = (l+r)//2
    a[m], a[m-1] = a[m-1], a[m]
    sl(l,m)
    sl(m, r)
sl(0, n)
if k != 0:
    exit(print(-1))
print(' '.join([str(i) for i in a]))


n,m = list(map(int, raw_input().split()))
res = []
def solve(begin, end, rem):
	#print('Solve:', begin, end, rem)
	if rem<2:
		res.extend(range(begin,end))
		return rem
	if end-begin==1:
		res.append(begin)
		return rem
	rem -= 2
	mid = (begin+end+1)//2
	rem = solve(mid, end, rem)
	rem = solve(begin, mid, rem)
	return rem
rem = solve(1, n+1, m-1)
if rem == 0:
	print(' '.join(map(str, res)))
else:
	print(-1)


n, k = map(int,input().split())
if k % 2 == 0:
    exit(print(-1))
k -= 1
a = [i+1 for i in range(n)]
def sl(l,r):
    global k
    if r-l < 2 or k == 0:
        return
    k -= 2
    m = (l+r)//2
    a[m], a[m-1] = a[m-1], a[m]
    sl(l,m)
    sl(m, r)
sl(0, n)
if k != 0:
    exit(print -1)
print(' '.join([str(i) for i in a]))


#include<stdio.h>
#include<stdlib.h>
int x=1;
void unsort(int a[],int low, int high,int k) {
   int mid;
   mid = (low + high) / 2;
   for(int i=low,j=high;i<j;i++,j--)
   {
       int temp=a[i];
       a[i]=a[j];
       a[j]=temp;
    }
    k-=4;
    k--;
   if(x<k) {
      unsort(a,low, mid,k/=2);
      unsort(a,mid+1, high,k/=2);
   } else {
      return;
   }
}
int main()
{
    int n,k;
    scanf("%d %d",&n,&k);
    int a[n];
    for(int i=0;i<n;i++)
    a[i]=i+1;
    if(k%2==0||k>2*n-1)
    {
        printf("-1");
        return 0;
    }
    else
    {
        if(k>2)
        {
            int mid=(n-1)/2;
            x+=2;
            unsort(a,0,mid,k--);
            unsort(a,mid+1,n-1,k--);
        }

        for(int i=0;i<n;i++)
        printf("%d ",a[i]);
    }
}


#include<stdio.h>
#include<stdlib.h>
int x=1;
void unsort(int a[],int low, int high,int k) {
   int mid;
   mid = (low + high) / 2;
   for(int i=low,j=high;i<j;i++,j--)
   {
       int temp=a[i];
       a[i]=a[j];
       a[j]=temp;
    }
    k--;
   if(x<k) {
      unsort(a,low, mid,k/=2);
      unsort(a,mid+1, high,k/=2);
   } else {
      return;
   }
}
int main()
{
    int n,k;
    scanf("%d %d",&n,&k);
    int a[n];
    for(int i=0;i<n;i++)
    a[i]=i+1;
    if(k%2==0||k>2*n-1)
    {
        printf("-1");
        return 0;
    }
    else
    {
        if(k>2)
        {
            int mid=(n-1)/2;
            x+=2;
            unsort(a,0,mid,k--);
            unsort(a,mid+1,n-1,k--);
        }

        for(int i=0;i<n;i++)
        printf("%d ",a[i]);
    }
}


#include<stdio.h>
#include<stdlib.h>
int x=1;
void unsort(int a[],int low, int high,int k) {
   int mid;
   mid = (low + high) / 2;
   if(low<high)
   {
       int temp=a[mid+1];
       a[mid+1]=a[mid];
       a[mid]=temp;
   }
   if(x<k) {
       x+=2;
      unsort(a,low, mid,k);
      unsort(a,mid+1, high,k);
   } else {
      return;
   }
}
int main()
{
    int n,k;
    scanf("%d %d",&n,&k);
    int a[n];
    for(int i=0;i<n;i++)
    a[i]=i+1;
    if(k%2==0||k>2*n-1)
    {
        printf("-1");
        return 0;
    }
    else
    {
        if(k>2)
        {
            int mid=(n-1)/2;
            int temp=a[mid];
            a[mid]=a[mid+1];
            a[mid+1]=temp;
            x+=2;
            unsort(a,0,mid,k);
            unsort(a,mid+1,n-1,k);
        }

        for(int i=0;i<n;i++)
        printf("%d ",a[i]);
    }
}


#include<stdio.h>
#include<stdlib.h>
int b[100005];
void merging(int a[],int low, int mid, int high) {
   int l1, l2, i;

   for(l1 = low, l2 = mid + 1, i = low; l1 <= mid && l2 <= high; i++) {
      if(a[l1] >= a[l2])
         b[i] = a[l1++];
      else
         b[i] = a[l2++];
   }

   while(l1 <= mid)
      b[i++] = a[l1++];

   while(l2 <= high)
      b[i++] = a[l2++];

   for(i = low; i <= high; i++)
      a[i] = b[i];
}
void unsort(int a[],int low, int high,int k) {
   int mid;

   if(k>0) {
      mid = (low + high) / 2;
      unsort(a,low, mid,k-=2);
      unsort(a,mid+1, high,k-=2);
      merging(a,low, mid, high);
   } else {
      return;
   }
}
int main()
{
    int n,k;
    scanf("%d %d",&n,&k);
    int a[n];
    for(int i=0;i<n;i++)
    a[i]=i+1;
    if(k%2==0||k>2*n)
    {
        printf("-1");
        return 0;
    }
    else
    {
        k--;
        unsort(a,0,n-1,k);
        for(int i=0;i<n;i++)
        printf("%d ",a[i]);
    }
}


#include<stdio.h>
#include<stdlib.h>
int x=1;
void unsort(int a[],int low, int high,int k) {
   int mid;
   mid = (low + high) / 2;
   for(int i=low,j=high;i<j;i++,j--)
   {
       int temp=a[i];
       a[i]=a[j];
       a[j]=temp;
    }
    k-=16;
   if(x<k) {
      unsort(a,low, mid,k/=2);
      unsort(a,mid+1, high,k/=2);
   } else {
      return;
   }
}
int main()
{
    int n,k;
    scanf("%d %d",&n,&k);
    int a[n];
    for(int i=0;i<n;i++)
    a[i]=i+1;
    if(k%2==0||k>2*n-1)
    {
        printf("-1");
        return 0;
    }
    else
    {
        if(k>2)
        {
            int mid=(n-1)/2;
            x+=2;
            unsort(a,0,mid,k--);
            unsort(a,mid+1,n-1,k--);
        }

        for(int i=0;i<n;i++)
        printf("%d ",a[i]);
    }
}


#include<stdio.h>
#include<stdlib.h>
int x=1;
void unsort(int a[],int low, int high,int k) {
   int mid;
   if(x<k&&low<high)
   {
       mid = (low + high) / 2;
      for(int i=low,j=mid;i<j;i++,j--)
      {
          int temp=a[i];
          a[i]=a[j];
          a[j]=temp;
       }
       k-=2;
      unsort(a,low, mid,k/=2);
      unsort(a,mid+1, high,k/=2);
   }
}
int main()
{
    int n,k;
    scanf("%d %d",&n,&k);
    int a[n];
    for(int i=0;i<n;i++)
    a[i]=i+1;
    if(k%2==0||k>2*n-1)
    {
        printf("-1");
        return 0;
    }
    else
    {
        if(k>2)
        {
            int mid=(n-1)/2;
            unsort(a,0,n-1,k--);
        }

        for(int i=0;i<n;i++)
        printf("%d ",a[i]);
    }
}


#include<stdio.h>

int arr[100001] ;

int n , k , total = 1 ;

void reverseMerge( int start , int end ){

    if( total == k || start + 1 == end ) return ;

    int mid = ( end + start ) / 2 ;

    if( mid - 1 < start ) return ;

    int temp = arr[mid] ;

    arr[mid] = arr[mid - 1] ;

    arr[mid - 1] = temp ;

    total += 2 ;

    reverseMerge( start , mid ) ;

    reverseMerge( mid , end ) ;
}

void solve(){

    scanf("%d %d",&n,&k) ;

    if( k % 2 == 0  ){

        printf("-1\n") ;

        return ;
    }

    for( int i = 0 ; i < n ; i++ )

        arr[i] = i + 1 ;

    reverseMerge( 0 , n ) ;

    if( total != k ){

        cout << -1 ;

        return ;
    }

    for( int i = 0 ; i < n ; i++ ) printf("%d ",arr[i]) ;
}

int main(){

    solve() ;

    return 0 ;
}


#include<stdio.h>
#include<stdlib.h>
int x=1;
void unsort(int a[],int low, int high,int k) {
   int mid;
   mid = (low + high) / 2;
   for(int i=low,j=high;i<j;i++,j--)
   {
       int temp=a[i];
       a[i]=a[j];
       a[j]=temp;
    }
    k--;
    k/=2;
   if(x<k) {
      unsort(a,low, mid,k/=2);
      unsort(a,mid+1, high,k/=2);
   } else {
      return;
   }
}
int main()
{
    int n,k;
    scanf("%d %d",&n,&k);
    int a[n];
    for(int i=0;i<n;i++)
    a[i]=i+1;
    if(k%2==0||k>2*n-1)
    {
        printf("-1");
        return 0;
    }
    else
    {
        if(k>2)
        {
            int mid=(n-1)/2;
            x+=2;
            unsort(a,0,mid,k--);
            unsort(a,mid+1,n-1,k--);
        }

        for(int i=0;i<n;i++)
        printf("%d ",a[i]);
    }
}


#include<stdio.h>
#include<stdlib.h>
int x=1;
void unsort(int a[],int low, int high,int k) {
   int mid;
   mid = (low + high) / 2;
   for(int i=low,j=high;i<j;i++,j--)
   {
       int temp=a[i];
       a[i]=a[j];
       a[j]=temp;
       k--;
   }
   if(x<k) {
      unsort(a,low, mid,k/=2);
      unsort(a,mid+1, high,k/=2);
   } else {
      return;
   }
}
int main()
{
    int n,k;
    scanf("%d %d",&n,&k);
    int a[n];
    for(int i=0;i<n;i++)
    a[i]=i+1;
    if(k%2==0||k>2*n-1)
    {
        printf("-1");
        return 0;
    }
    else
    {
        if(k>2)
        {
            int mid=(n-1)/2;
            x+=2;
            unsort(a,0,mid,k--);
            unsort(a,mid+1,n-1,k--);
        }

        for(int i=0;i<n;i++)
        printf("%d ",a[i]);
    }
}


#include<stdio.h>
#include<stdlib.h>
int x=1;
void unsort(int a[],int low, int high,int k) {
   int mid;
   if(x<k&&low<high)
   {
       mid = (low + high) / 2;
      for(int i=low,j=mid;i<j;i++,j--)
      {
          int temp=a[i];
          a[i]=a[j];
          a[j]=temp;
       }
       k/=2;
      unsort(a,low, mid,k/=2);
      unsort(a,mid+1, high,k/=2);
   }
}
int main()
{
    int n,k;
    scanf("%d %d",&n,&k);
    int a[n];
    for(int i=0;i<n;i++)
    a[i]=i+1;
    if(k%2==0||k>2*n-1)
    {
        printf("-1");
        return 0;
    }
    else
    {
        if(k>2)
        {
            int mid=(n-1)/2;
            unsort(a,0,n-1,k--);
        }

        for(int i=0;i<n;i++)
        printf("%d ",a[i]);
    }
}


#include<stdio.h>
#include<stdlib.h>
int x=1;
void unsort(int a[],int low, int high,int k) {
   int mid;
   mid = (low + high) / 2;
   for(int i=low,j=high;i<j;i++,j--)
   {
       int temp=a[i];
       a[i]=a[j];
       a[j]=temp;
   }
   if(x<k) {
       x+=2;
      unsort(a,low, mid,k);
      unsort(a,mid+1, high,k);
   } else {
      return;
   }
}
int main()
{
    int n,k;
    scanf("%d %d",&n,&k);
    int a[n];
    for(int i=0;i<n;i++)
    a[i]=i+1;
    if(k%2==0||k>2*n-1)
    {
        printf("-1");
        return 0;
    }
    else
    {
        if(k>2)
        {
            int mid=(n-1)/2;
            x+=2;
            unsort(a,0,mid,k);
            unsort(a,mid+1,n-1,k);
        }

        for(int i=0;i<n;i++)
        printf("%d ",a[i]);
    }
}


#include<stdio.h>
#include<stdlib.h>
int x=1;
void unsort(int a[],int low, int high,int k) {
   int mid;
   mid = (low + high) / 2;
   for(int i=low,j=high;i<j;i++,j--)
   {
       int temp=a[i];
       a[i]=a[j];
       a[j]=temp;
    }
    k-=2;
   if(x<k) {
      unsort(a,low, mid,k/=2);
      unsort(a,mid+1, high,k/=2);
   } else {
      return;
   }
}
int main()
{
    int n,k;
    scanf("%d %d",&n,&k);
    int a[n];
    for(int i=0;i<n;i++)
    a[i]=i+1;
    if(k%2==0||k>2*n-1)
    {
        printf("-1");
        return 0;
    }
    else
    {
        if(k>2)
        {
            int mid=(n-1)/2;
            x+=2;
            unsort(a,0,mid,k--);
            unsort(a,mid+1,n-1,k--);
        }

        for(int i=0;i<n;i++)
        printf("%d ",a[i]);
    }
}


#include<stdio.h>
#include<stdlib.h>
int x=1;
void unsort(int a[],int low, int high,int k) {
   int mid;
   if(x<k&&low<high)
   {
       mid = (low + high) / 2;
      for(int i=low,j=mid;i<j;i++,j--)
      {
          int temp=a[i];
          a[i]=a[j];
          a[j]=temp;
       }
      unsort(a,low, mid,k/=2);
      unsort(a,mid+1, high,k/=2);
   }
}
int main()
{
    int n,k;
    scanf("%d %d",&n,&k);
    int a[n];
    for(int i=0;i<n;i++)
    a[i]=i+1;
    if(k%2==0||k>2*n-1)
    {
        printf("-1");
        return 0;
    }
    else
    {
        if(k>2)
        {
            int mid=(n-1)/2;
            unsort(a,0,n-1,k--);
        }

        for(int i=0;i<n;i++)
        printf("%d ",a[i]);
    }
}


#include<stdio.h>
#include<stdlib.h>
int x=1;
void unsort(int a[],int low, int high,int k) {
   int mid;
   mid = (low + high) / 2;
   for(int i=low,j=high;i<j;i++,j--)
   {
       int temp=a[i];
       a[i]=a[j];
       a[j]=temp;
   }
   if(x<k) {
      unsort(a,low, mid,k/=2);
      unsort(a,mid+1, high,k/=2);
   } else {
      return;
   }
}
int main()
{
    int n,k;
    scanf("%d %d",&n,&k);
    int a[n];
    for(int i=0;i<n;i++)
    a[i]=i+1;
    if(k%2==0||k>2*n-1)
    {
        printf("-1");
        return 0;
    }
    else
    {
        if(k>2)
        {
            int mid=(n-1)/2;
            x+=2;
            unsort(a,0,mid,k);
            unsort(a,mid+1,n-1,k);
        }

        for(int i=0;i<n;i++)
        printf("%d ",a[i]);
    }
}


#include<stdio.h>
#include<stdlib.h>
int x=1;
void unsort(int a[],int low, int high,int k) {
   int mid;
   mid = (low + high) / 2;
   for(int i=low,j=high;i<j;i++,j--)
   {
       int temp=a[i];
       a[i]=a[j];
       a[j]=temp;
   }
   if(x<k) {
      unsort(a,low, mid,k/=2);
      unsort(a,mid+1, high,k/=2);
   } else {
      return;
   }
}
int main()
{
    int n,k;
    scanf("%d %d",&n,&k);
    int a[n];
    for(int i=0;i<n;i++)
    a[i]=i+1;
    if(k%2==0||k>2*n-1)
    {
        printf("-1");
        return 0;
    }
    else
    {
        if(k>2)
        {
            int mid=(n-1)/2;
            x+=2;
            unsort(a,0,mid,k--);
            unsort(a,mid+1,n-1,k--);
        }

        for(int i=0;i<n;i++)
        printf("%d ",a[i]);
    }
}