#include <iostream>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;
#define PR(x) cout << #x " = " << x << "\n";
int n;
int cnt1=0, cnt2=0, cnt3=0, cnt4=0, ans=0;
void merge1with2(std::vector<int> &in)
{

    std::vector<int> ::iterator it1=in.begin();
    std::vector<int> ::iterator it2=lower_bound(in.begin(), in.end(), 3); it2--;
    while(it1!=in.end() && it2!=in.end() && *it1==1 && *it2==2)
    {
        *it1=0; cnt1--;
        *it2=3; cnt2--; cnt3++;
        ans++;
        it1++; it2--;
    }
    it1=upper_bound(in.begin(), in.end(), 0);
    if(it1==in.begin()) in.erase(in.begin());
    else in.erase(in.begin(), it1);
    /*for (int i = 0; i < in.size(); ++i)
    {
        cout<<in[i]<<" ";
    }
    cout<<endl;*/

}
void merge1with3(std::vector<int> &in)
{
    /*for (int i = 0; i < in.size(); ++i)
    {
        cout<<in[i]<<" ";
    }
    cout<<endl;*/
    std::vector<int> ::iterator it1=in.begin();
    std::vector<int> ::iterator it3=lower_bound(in.begin(), in.end(), 4); it3--;
    while(it1!=in.end() && it3!=in.end() && *it1==1 && *it3==3)
    {
        *it1=0; cnt1--;
        *it3=4; cnt3--; cnt4++;
        ans++;
        it1++; it3--;
    }
    it1=upper_bound(in.begin(), in.end(), 0);
    if(it1==in.begin()) in.erase(in.begin());
    in.erase(in.begin(), it1);
    /*for (int i = 0; i < in.size(); ++i)
    {
        cout<<in[i]<<" ";
    }
    cout<<endl;
    PR(ans);*/

}
void from4to2(std::vector<int> &in)
{
    std::vector<int> :: iterator it2=lower_bound(in.begin(), in.end(), 3); it2--;
    std::vector<int> :: iterator it4=lower_bound(in.begin(), in.end(), 4);
    while(it2!=in.end() && it4!=in.end() && *it2==2 && *it4==4)
    {
        *it4=3; cnt4--; cnt3++;
        *it2=3; cnt2--; cnt3++;
        ans++;
        it2--; it4++;
    }

}
int main(int argc, char const *argv[])
{
    ios_base::sync_with_stdio(0);
    int n, temp; cin>>n;
    std::vector<int> in;
    for (int i = 0; i < n; ++i)
    {
        cin>>temp;
        in.push_back(temp);
        if(in[i]==1) cnt1++;
        if(in[i]==2) cnt2++;
        if(in[i]==3) cnt3++;
        if(in[i]==4) cnt4++;
    }
    sort(in.begin(), in.end());
    if(cnt1!=0 && cnt2!=0 ) merge1with2(in);
    if (cnt1==0 && cnt2==0) { cout<<ans; return 0; }
    else if (cnt1==0) //2 3 4 left
    {
        from4to2(in);
        if(cnt2==0) { cout<<ans; return 0; }
        else
        {
            if(cnt2%3!=0) { cout<<-1; return 0; }
            else {cout<<ans + cnt2/3; return 0; }
        }
    }
    else // 1 3 4 left
    {
        merge1with3(in);
        if(cnt1==0) { cout<<ans; return 0; }
        else
        {
            ans+=(2*cnt1)/3; cnt3+=cnt1/3; cnt1=cnt1%3;
            if(cnt1==0) { cout<<ans; return 0; }
            else
            {
                if(cnt1==1 && cnt3==0) { cout<<-1; return 0; }
                else if(cnt1==1 && cnt3>0) { cout<<ans+1; return 0; }
                else if(cnt1==2)
                {
                    ans++;
                    if(cnt4>0) { cout<<ans+1; return 0; }
                    else { cout<<-1; return 0; }
                }
            }
        }
    }
    return 0;
}


#include <iostream>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;
#define PR(x) cout << #x " = " << x << "\n";
int n;
int cnt1=0, cnt2=0, cnt3=0, cnt4=0, ans=0;
void merge1with2(std::vector<int> &in)
{

    std::vector<int> ::iterator it1=in.begin();
    std::vector<int> ::iterator it2=lower_bound(in.begin(), in.end(), 3); it2--;
    while(it1!=in.end() && it2!=in.end() && *it1==1 && *it2==2)
    {
        *it1=0; cnt1--;
        *it2=3; cnt2--; cnt3++;
        ans++;
        it1++; it2--;
    }
    it1=upper_bound(in.begin(), in.end(), 0);
    if(it1==in.begin()) in.erase(in.begin());
    else in.erase(in.begin(), it1);
    /*for (int i = 0; i < in.size(); ++i)
    {
        cout<<in[i]<<" ";
    }
    cout<<endl;*/

}
void merge1with3(std::vector<int> &in)
{
    /*for (int i = 0; i < in.size(); ++i)
    {
        cout<<in[i]<<" ";
    }
    cout<<endl;*/
    std::vector<int> ::iterator it1=in.begin();
    std::vector<int> ::iterator it3=lower_bound(in.begin(), in.end(), 4); it3--;
    while(it1!=in.end() && it3!=in.end() && *it1==1 && *it3==3)
    {
        *it1=0; cnt1--;
        *it3=4; cnt3--; cnt4++;
        ans++;
        it1++; it3--;
    }
    it1=upper_bound(in.begin(), in.end(), 0);
    if(it1==in.begin()) in.erase(in.begin());
    in.erase(in.begin(), it1);
    /*for (int i = 0; i < in.size(); ++i)
    {
        cout<<in[i]<<" ";
    }
    cout<<endl;
    PR(ans);*/

}
void from4to2(std::vector<int> &in)
{
    std::vector<int> :: iterator it2=lower_bound(in.begin(), in.end(), 3); it2--;
    std::vector<int> :: iterator it4=lower_bound(in.begin(), in.end(), 4);
    while(it2!=in.end() && it4!=in.end() && *it2==2 && *it4==4)
    {
        *it4=3; cnt4--; cnt3++;
        *it2=3; cnt2--; cnt3++;
        ans++;
        it2--; it4++;
    }

}
int main(int argc, char const *argv[])
{
    ios_base::sync_with_stdio(0);
    int n, temp; cin>>n;
    std::vector<int> in;
    for (int i = 0; i < n; ++i)
    {
        cin>>temp;
        in.push_back(temp);
        if(in[i]==1) cnt1++;
        if(in[i]==2) cnt2++;
        if(in[i]==3) cnt3++;
        if(in[i]==4) cnt4++;
    }
    sort(in.begin(), in.end());
    if(cnt1!=0 && cnt2!=0 ) merge1with2(in);
    if (cnt1==0 && cnt2==0) { cout<<ans; return 0; }
    else if (cnt1==0) //2 3 4 left
    {
        from4to2(in);
        if(cnt2==0) { cout<<ans; return 0; }
        else
        {
            if(cnt2%3!=0) { cout<<-1; return 0; }
            else {cout<<ans + cnt2/3; return 0; }
        }
    }
    else // 1 3 4 left
    {
        merge1with3(in);
        if(cnt1==0) { cout<<ans; return 0; }
        else
        {
            if(cnt1=cnt4*2) { cout<<ans+cnt1; return 0; }
            else { cout<<-1; return 0; }
        }
    }
    return 0;
}


#include <iostream>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;
#define PR(x) cout << #x " = " << x << "\n";
int n;
int cnt1=0, cnt2=0, cnt3=0, cnt4=0, ans=0;
void merge1with2(std::vector<int> &in)
{

    std::vector<int> ::iterator it1=in.begin();
    std::vector<int> ::iterator it2=lower_bound(in.begin(), in.end(), 3); it2--;
    while(it1!=in.end() && it2!=in.end() && *it1==1 && *it2==2)
    {
        *it1=0; cnt1--;
        *it2=3; cnt2--; cnt3++;
        ans++;
        it1++; it2--;
    }
    it1=upper_bound(in.begin(), in.end(), 0);
    if(it1==in.begin()) in.erase(in.begin());
    else in.erase(in.begin(), it1);
    /*for (int i = 0; i < in.size(); ++i)
    {
        cout<<in[i]<<" ";
    }
    cout<<endl;*/

}
void merge1with3(std::vector<int> &in)
{
    /*for (int i = 0; i < in.size(); ++i)
    {
        cout<<in[i]<<" ";
    }
    cout<<endl;*/
    std::vector<int> ::iterator it1=in.begin();
    std::vector<int> ::iterator it3=lower_bound(in.begin(), in.end(), 4); it3--;
    while(it1!=in.end() && it3!=in.end() && *it1==1 && *it3==3)
    {
        *it1=0; cnt1--;
        *it3=4; cnt3--; cnt4++;
        ans++;
        it1++; it3--;
    }
    it1=upper_bound(in.begin(), in.end(), 0);
    if(it1==in.begin()) in.erase(in.begin());
    in.erase(in.begin(), it1);
    /*for (int i = 0; i < in.size(); ++i)
    {
        cout<<in[i]<<" ";
    }
    cout<<endl;
    PR(ans);*/

}
void from4to2(std::vector<int> &in)
{
    std::vector<int> :: iterator it2=lower_bound(in.begin(), in.end(), 3); it2--;
    std::vector<int> :: iterator it4=lower_bound(in.begin(), in.end(), 4);
    while(it2!=in.end() && it4!=in.end() && *it2==2 && *it4==4)
    {
        *it4=3; cnt4--; cnt3++;
        *it2=3; cnt2--; cnt3++;
        ans++;
        it2--; it4++;
    }
    /*for (int i = 0; i < in.size(); ++i)
    {
        cout<<in[i]<<" ";
    }
    cout<<endl;
    PR(ans);*/

}
int main(int argc, char const *argv[])
{
    ios_base::sync_with_stdio(0);
    int n, temp; cin>>n;
    std::vector<int> in;
    for (int i = 0; i < n; ++i)
    {
        cin>>temp;
        in.push_back(temp);
        if(in[i]==1) cnt1++;
        if(in[i]==2) cnt2++;
        if(in[i]==3) cnt3++;
        if(in[i]==4) cnt4++;
    }
    sort(in.begin(), in.end());
    if(cnt1!=0 && cnt2!=0 ) merge1with2(in);
    if (cnt1==0 && cnt2==0) { cout<<ans; return 0; }
    else if (cnt1==0) //2 3 4 left
    {
        from4to2(in);
        if(cnt2==0) { cout<<ans; return 0; }
        else
        {
            if(cnt2%3!=0) { cout<<-1; return 0; }
            else {cout<<ans + 2*(cnt2/3); return 0; }
        }
    }
    else // 1 3 4 left
    {
        merge1with3(in);
        if(cnt1==0) { cout<<ans; return 0; }
        else
        {
            ans+=2*(cnt1/3); cnt3+=cnt1/3; cnt1=cnt1%3;
            if(cnt1==0) { cout<<ans; return 0; }
            else
            {
                if(cnt1==1 && cnt3==0) { cout<<-1; return 0; }
                else if(cnt1==1 && cnt3>0) { cout<<ans+1; return 0; }
                else if(cnt1==2)
                {
                    ans++;
                    if(cnt4>0) { cout<<ans+1; return 0; }
                    else { cout<<-1; return 0; }
                }
            }
        }
    }
    return 0;
}


#include <iostream>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;
#define PR(x) cout << #x " = " << x << "\n";
int n;
int cnt1=0, cnt2=0, cnt3=0, cnt4=0, ans=0;
void merge1with2(std::vector<int> &in)
{

    std::vector<int> ::iterator it1=in.begin();
    std::vector<int> ::iterator it2=lower_bound(in.begin(), in.end(), 3); it2--;
    while(it1!=in.end() && it2!=in.end() && *it1==1 && *it2==2)
    {
        *it1=0; cnt1--;
        *it2=3; cnt2--; cnt3++;
        ans++;
        it1++; it2--;
    }
    it1=upper_bound(in.begin(), in.end(), 0);
    if(it1==in.begin()) in.erase(in.begin());
    else in.erase(in.begin(), it1);
    /*for (int i = 0; i < in.size(); ++i)
    {
        cout<<in[i]<<" ";
    }
    cout<<endl;*/

}
void merge1with3(std::vector<int> &in)
{
    /*for (int i = 0; i < in.size(); ++i)
    {
        cout<<in[i]<<" ";
    }
    cout<<endl;*/
    std::vector<int> ::iterator it1=in.begin();
    std::vector<int> ::iterator it3=lower_bound(in.begin(), in.end(), 4); it3--;
    while(it1!=in.end() && it3!=in.end() && *it1==1 && *it3==3)
    {
        *it1=0; cnt1--;
        *it3=4; cnt3--; cnt4++;
        ans++;
        it1++; it3--;
    }
    it1=upper_bound(in.begin(), in.end(), 0);
    if(it1==in.begin()) in.erase(in.begin());
    in.erase(in.begin(), it1);
    /*for (int i = 0; i < in.size(); ++i)
    {
        cout<<in[i]<<" ";
    }
    cout<<endl;
    PR(ans);*/

}
void from4to2(std::vector<int> &in)
{
    std::vector<int> :: iterator it2=lower_bound(in.begin(), in.end(), 3); it2--;
    std::vector<int> :: iterator it4=lower_bound(in.begin(), in.end(), 4);
    while(it2!=in.end() && it4!=in.end() && *it2==2 && *it4==4)
    {
        *it4=3; cnt4--; cnt3++;
        *it2=3; cnt2--; cnt3++;
        ans++;
        it2--; it4++;
    }

}
int main(int argc, char const *argv[])
{
    ios_base::sync_with_stdio(0);
    int n, temp; cin>>n;
    std::vector<int> in;
    for (int i = 0; i < n; ++i)
    {
        cin>>temp;
        in.push_back(temp);
        if(in[i]==1) cnt1++;
        if(in[i]==2) cnt2++;
        if(in[i]==3) cnt3++;
        if(in[i]==4) cnt4++;
    }
    sort(in.begin(), in.end());
    if(cnt1!=0 && cnt2!=0 ) merge1with2(in);
    if (cnt1==0 && cnt2==0) { cout<<ans; return 0; }
    else if (cnt1==0) //2 3 4 left
    {
        from4to2(in);
        if(cnt2==0) { cout<<ans; return 0; }
        else
        {
            if(cnt2%3!=0) { cout<<-1; return 0; }
            else {cout<<ans + cnt2/3; return 0; }
        }
    }
    else // 1 3 4 left
    {
        merge1with3(in);
        if(cnt1==0) { cout<<ans; return 0; }
        else
        {
            ans+=2*(cnt1/3); cnt3+=cnt1/3; cnt1=cnt1%3;
            if(cnt1==0) { cout<<ans; return 0; }
            else
            {
                if(cnt1==1 && cnt3==0) { cout<<-1; return 0; }
                else if(cnt1==1 && cnt3>0) { cout<<ans+1; return 0; }
                else if(cnt1==2)
                {
                    ans++;
                    if(cnt4>0) { cout<<ans+1; return 0; }
                    else { cout<<-1; return 0; }
                }
            }
        }
    }
    return 0;
}


#include <iostream>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;
#define PR(x) cout << #x " = " << x << "\n";
int n;
int cnt1=0, cnt2=0, cnt3=0, cnt4=0, ans=0;
void merge1with2(std::vector<int> &in)
{

    std::vector<int> ::iterator it1=in.begin();
    std::vector<int> ::iterator it2=lower_bound(in.begin(), in.end(), 3); it2--;
    while(it1!=in.end() && it2!=in.end() && *it1==1 && *it2==2)
    {
        *it1=0; cnt1--;
        *it2=3; cnt2--; cnt3++;
        ans++;
        it1++; it2--;
    }
    it1=upper_bound(in.begin(), in.end(), 0);
    if(it1==in.begin()) in.erase(in.begin());
    else in.erase(in.begin(), it1);
    /*for (int i = 0; i < in.size(); ++i)
    {
        cout<<in[i]<<" ";
    }
    cout<<endl;*/

}
void merge1with3(std::vector<int> &in)
{
    /*for (int i = 0; i < in.size(); ++i)
    {
        cout<<in[i]<<" ";
    }
    cout<<endl;*/
    std::vector<int> ::iterator it1=in.begin();
    std::vector<int> ::iterator it3=lower_bound(in.begin(), in.end(), 4); it3--;
    while(it1!=in.end() && it3!=in.end() && *it1==1 && *it3==3)
    {
        *it1=0; cnt1--;
        *it3=4; cnt3--; cnt4++;
        ans++;
        it1++; it3--;
    }
    it1=upper_bound(in.begin(), in.end(), 0);
    if(it1==in.begin()) in.erase(in.begin());
    in.erase(in.begin(), it1);
    /*for (int i = 0; i < in.size(); ++i)
    {
        cout<<in[i]<<" ";
    }
    cout<<endl;
    PR(ans);*/

}
void from4to2(std::vector<int> &in)
{
    std::vector<int> :: iterator it2=lower_bound(in.begin(), in.end(), 3); it2--;
    std::vector<int> :: iterator it4=lower_bound(in.begin(), in.end(), 4);
    while(it2!=in.end() && it4!=in.end() && *it2==2 && *it4==4)
    {
        *it4=3; cnt4--; cnt3++;
        *it2=3; cnt2--; cnt3++;
        ans++;
        it2--; it4++;
    }

}
int main(int argc, char const *argv[])
{
    ios_base::sync_with_stdio(0);
    int n, temp; cin>>n;
    std::vector<int> in;
    for (int i = 0; i < n; ++i)
    {
        cin>>temp;
        in.push_back(temp);
        if(in[i]==1) cnt1++;
        if(in[i]==2) cnt2++;
        if(in[i]==3) cnt3++;
        if(in[i]==4) cnt4++;
    }
    sort(in.begin(), in.end());
    if(cnt1!=0 && cnt2!=0 ) merge1with2(in);
    if (cnt1==0 && cnt2==0) { cout<<ans; return 0; }
    else if (cnt1==0) //2 3 4 left
    {
        from4to2(in);
        if(cnt2==0) { cout<<ans; return 0; }
        else
        {
            if(cnt2%3!=0) { cout<<-1; return 0; }
            else {cout<<ans + cnt2/3; return 0; }
        }
    }
    else // 1 3 4 left
    {
        merge1with3(in);
        if(cnt1==0) { cout<<ans; return 0; }
        else
        {
            ans+=cnt1/3; cnt3+=cnt1/3; cnt1=cnt1%3;
            if(cnt1==0) { cout<<ans; return 0; }
            else
            {
                if(cnt1==1 && cnt3==0) { cout<<-1; return 0; }
                else if(cnt1==1 && cnt3>0) { cout<<ans+1; return 0; }
                else if(cnt1==2)
                {
                    ans++;
                    if(cnt4>0) { cout<<ans+1; return 0; }
                    else { cout<<-1; return 0; }
                }
            }
        }
    }
    return 0;
}


#include <iostream>
#include <cstring>

using namespace std;

int sum[5]={0}, ans=0;

int main()
{
	int n;
	cin>>n;
	for(int i=0; i<n; i++)
	{
		int a; cin>>a;
		if(a) sum[a]++;
	}
	//while(sum[1]>1) sum[2]++, sum[1]-=2, ans++;
	while(sum[1])
	{
		if(sum[2]) sum[3]++, sum[2]--, sum[1]--, ans++;
		else if(sum[1]>1) sum[2]++, sum[1]--, ans++;
		else if(sum[3]) sum[4]++, sum[1]--, sum[3]--, ans++;
	}
	while(sum[2] && (sum[1] || sum[4]))
	{
		if(sum[2]>2) sum[2]-=3, sum[3]+=2, ans+=2;
		else if(sum[2]>1) sum[2]-=2, sum[4]++, ans++;
		else if(sum[4]) sum[3]++, sum[2]--, sum[4]--, ans++;
	}
	if(sum[1]||sum[2]) cout<<-1<<endl;
	else cout<<ans<<endl;
}


#include <iostream>
#include <cstring>

using namespace std;

int sum[5]={0}, ans=0;

int main()
{
	int n;
	cin>>n;
	for(int i=0; i<n; i++)
	{
		int a; cin>>a;
		if(a) sum[a]++;
	}
	//while(sum[1]>1) sum[2]++, sum[1]-=2, ans++;
	while(sum[1])
	{
		if(sum[2]) sum[3]++, sum[2]--, sum[1]--, ans++;
		else if(sum[1]>1) sum[2]++, sum[1]--, ans++;
		else if(sum[3]) sum[4]++, sum[1]--, ans++;
	}
	while(sum[2] && (sum[1] || sum[4]))
	{
		if(sum[2]>2) sum[2]-=3, sum[3]+=2, ans+=2;
		else if(sum[2]>1) sum[2]-=2, sum[4]++, ans++;
		else if(sum[4]) sum[3]++, sum[2]--, sum[4]--, ans++;
	}
	if(sum[1]||sum[2]) cout<<-1<<endl;
	else cout<<ans<<endl;
}


#include <iostream>
#include <cstring>

using namespace std;

int sum[5]={0}, ans=0;

int main()
{
	int n;
	cin>>n;
	for(int i=0; i<n; i++)
	{
		int a; cin>>a;
		if(a) sum[a]++;
	}
	//while(sum[1]>1) sum[2]++, sum[1]-=2, ans++;
	while(sum[1])
	{
		if(sum[2]) sum[3]++, sum[2]--, sum[1]--, ans++;
		else if(sum[1]>1) sum[2]++, sum[1]-=2, ans++;
		else if(sum[3]) sum[4]++, sum[1]--, sum[3]--, ans++;
	}
	while(sum[2] && (sum[1] || sum[4]))
	{
		if(sum[2]>2) sum[2]-=3, sum[3]+=2, ans+=2;
		else if(sum[2]>1) sum[2]-=2, sum[4]++, ans++;
		else if(sum[4]) sum[3]++, sum[2]--, sum[4]--, ans++;
	}
	if(sum[1]||sum[2]) cout<<-1<<endl;
	else cout<<ans<<endl;
}


#include <iostream>
#include <cstring>

using namespace std;

int sum[5]={0}, ans=0;

int main()
{
	int n;
	cin>>n;
	for(int i=0; i<n; i++)
	{
		int a; cin>>a;
		if(a) sum[a]++;
	}
	while(sum[1]>1) sum[2]++, sum[1]-=2, ans++;
	while(sum[2] && (sum[1] || sum[4]))
	{
		if(sum[1]) sum[3]++, sum[2]--, sum[1]--, ans++;
		else if(sum[2]>1) sum[2]-=2, sum[4]++, ans++;
		else if(sum[4]) sum[3]++, sum[2]--, sum[4]--, ans++;
	}
	while(sum[1])
	{
		if(sum[1]>2) sum[1]-=3, sum[3]++, ans+=2;
		else if(sum[3]) sum[3]--, sum[4]++, ans+=1, sum[1]--;
		else if(sum[1]>1 || sum[4]) sum[4]--, ans+=2, sum[1]-=2, sum[3]++;
	}
	if(sum[1]||sum[2]) cout<<-1<<endl;
	else cout<<ans<<endl;
}


#include <iostream>
#include <cstring>

using namespace std;

int sum[5]={0}, ans=0;

int main()
{
	int n;
	cin>>n;
	for(int i=0; i<n; i++)
	{
		int a; cin>>a;
		if(a) sum[a]++;
	}
	while(sum[2] && (sum[1] || sum[4]))
	{
		if(sum[1]) sum[3]++, sum[2]--, sum[1]--, ans++;
		else if(sum[2]>1) sum[2]-=2, sum[4]++, ans+=2;
		else if(sum[4]) sum[3]++, sum[2]--, sum[4]--, ans++;
	}
	while(sum[1])
	{
		if(sum[1]>2) sum[1]-=3, sum[3]++, ans+=2;
		else if(sum[3]) sum[3]--, sum[4]++, ans+=1, sum[1]--;
		else if(sum[1]>1 || sum[4]) sum[4]--, ans+=2, sum[1]-=2, sum[3]++;
	}
	if(sum[1]||sum[2]) cout<<-1<<endl;
	else cout<<ans<<endl;
}


// inplace_merge(T + beg, T + mid + 1, T + end + 1);
// unsigned Long hash[maxn],p = 999999999989; hash[0] = 1; fo(i,1,maxn)hash[i] = hash[i-1] * p;
// __builtin_popcount(n);
/*
ID: Tariqul
PROG:
LANG: C++
*/

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <unistd.h> // sleep(1)

using namespace std;

#define fo(i,j,n) for(i=j;i<n;++i)
#define Fo(i,j,n) for(i=n-1;i>=j;--i)
#define foo(i,j,v) fo(i,j,sz(v))
#define Foo(i,j,v) Fo(i,j,sz(v))
#define li(v) v.begin(),v.end()
#define sz(v) ((int)v.size())
#define CLR(a,v) memset((a),(v),sizeof(a))
#define inf 1e9 + 10
#ifdef localhost
#define Long long long
#else
typedef __int64 Long;
#endif // localhost
#define pi (2*acos(0))
#define eps 1e-9

#define two(X) (1<<(X))
#define twoL(X) (((Long)(1))<<(X))
#define contain(S,X) (((S)&two(X))!=0)
#define containL(S,X) (((S)&twoL(X))!=0)

char BUFFER[100000 + 5];
bool readn(int &n)	{ return scanf("%d",&n) == 1; }
#ifdef localhost
bool readl(Long &n)	{ return scanf("%lld",&n) == 1; }
#else
bool readl(Long &n)	{ return scanf("%I64d",&n) == 1; }
#endif // localhost
bool readd(double &n){ return scanf("%lf",&n) == 1; }
bool reads(string &s){ s = ""; int n = scanf("%s",BUFFER); if(n == 1)s = BUFFER; return n == 1; }
bool readln(string &s){ char *valid = gets(BUFFER); if(valid)s = BUFFER; return ((bool)valid); }
#ifdef localhost
void Print(Long &n, bool printNewLine = true)	{ printNewLine ? printf("%lld\n",n) : printf("%lld",n);  }
#else
void Print(Long &n, bool printNewLine = true)	{ printNewLine ? printf("%I64d\n",n) :  printf("%I64d",n); }
#endif // localhost

const int maxn = 1e6 + 10;
int cnt[maxn][5];

int calc(int u, int v, int w)
{
    if(u > v)return 0;
    int ans = 0,total,i;

    fo(i,0,5)
    {
        total = cnt[v][i];
        if(u>0) total -= cnt[u-1][i];

        int cost = abs(i-w);
        ans += cost * total;
    }

    return ans;
}

vector<int> v;

int main()
{
	#ifdef localhost
    freopen("/home/tariqul/APC/Contest/input.txt","r",stdin);
    //freopen("/home/tariqul/APC/Contest/output.txt","w",stdout);
	#else
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	#endif

    int i,j,n,mi = inf,sum = 0,cnt3,cnt4,val; cin >> n; v.resize(n);
    foo(i,0,v){ readn(v[i]); sum += v[i]; }
    sort(li(v)); reverse(li(v));

    fo(j,0,5)fo(i,0,n)
    {
        if(i == 0)cnt[i][j] = (v[i]==j);
        else cnt[i][j] = (cnt[i-1][j] + (v[i]==j));
    }

    for(cnt4 = 0; cnt4 <= n; ++cnt4)
    {
        int rim = sum - cnt4*4;
        if(rim < 0)continue;
        if(rim % 3 != 0)continue;
        cnt3 = rim/3;
        if(cnt4 + cnt3 > n) continue;
        val = calc(0,cnt4-1,4) + calc(cnt4,cnt4+cnt3-1,3) + calc(cnt4+cnt3,n-1,0);
        mi = min(mi,val);
    }

    if(mi == inf)mi = -1;
    else mi /= 2;
    cout << mi << endl;
    return 0;
}


#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
using namespace std;
#define inf (1061109567)
#define rep(i,n) for(int i(0);(i)<(n);++(i))
#define mst(x, a) memset(x,(a),sizeof x)
typedef __int64 ll;
int c[5];
int main()
{
    int n, x, t, s = 0;
    cin >> n;
    rep(i, n) {
        cin >> x;
        c[x] += 1;
    }
    t = min(c[1], c[2]);
    c[1] -= t, c[2] -= t, s += t, c[3] += t;
    if (c[1]) {
        t = c[1] / 3; c[1] %= 3; s += t + t; c[3] += t;
        if (c[1]) {
            if (c[1] == 1) {
                if (c[3] >= 1) s += 1;
                else if (c[4] >= 2) s += 2;
                else s = -1;
            }
            else {
                if (c[4] >= 1 || c[3] >= 2) s += 2;
                else s = -1;
            }
        }
    }
    if (c[2]) {
        t = c[2] / 3; c[2] %= 3; s += t + t; c[3] += t + t;
        if (c[2]) {
            if (c[2] == 1) {
                if (c[4] >= 1) s += 1;
                else if (c[3] >= 2) s += 2;
                else s = -1;
            }
            else {
                s += 2;
            }
        }
    }
    cout << s << endl;
    return 0;
}


#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
using namespace std;
#define inf (1061109567)
#define rep(i,n) for(int i(0);(i)<(n);++(i))
#define mst(x, a) memset(x,(a),sizeof x)
typedef __int64 ll;
int c[5];
int main()
{
    int n, x, t, s = 0;
    cin >> n;
    rep(i, n) {
        cin >> x;
        c[x] += 1;
    }
    t = min(c[1], c[2]);
    c[1] -= t, c[2] -= t, s += t;
    if (c[1]) {
        t = c[1] / 3; c[1] %= 3; s += t + t;
        if (c[1]) {
            if (c[1] == 1) {
                if (c[4] >= 2) s += 2;
            }
            else {
                if (c[4] >= 1) s += 2;
            }
        }
    }
    if (c[2]) {
        t = c[2] / 3; c[2] %= 3; s += t + t;
        if (c[2]) {
            if (c[2] == 1) {
                if (c[4] >= 1) s += 1;
            }
            else {
                s += 1;
                if (c[4] >= 2) s += 2;
            }
        }
    }
    cout << s << endl;
    return 0;
}


						/*////////////////////////////////////////////////*/
						/* 				 code by d@rk$(@!e   			  */
						/*////////////////////////////////////////////////*/
#include <algorithm>
#include <assert.h>
#include <fstream>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#include <cctype>
#include <climits>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <cstring>

using namespace std;
#define CLR(a) memset(a, 0, sizeof(a))
#define ABS(X) ( (X) > 0 ? (X) : ( -(X) ) )
#define SZ(V) (int )V.size()
#define ALL(V) V.begin(), V.end()
#define RALL(V) V.rbegin(), V.rend()
#define FORN(i, n) for(i = 0; i < n; i++)
#define FORAB(i, a, b) for(i = a; i <= b; i++)
#define si(n) scanf("%d",&n)
#define ss(s) scanf("%s",s)
#define prin(n) printf("%d\n",n)
#define psi pair < string, int >
#define MOD 1000000007LL
#define PB push_back
#define MP make_pair
#define F first
#define S second

typedef long long LL;
typedef pair<int,int> pii;
typedef pair<double, double> PDD;
typedef pair<LL,LL> pll;
template<class T> string toString(T value){ostringstream sout;sout<<value;return sout.str(); }

int main()
{
	int i,j,k,n,a[5];
	memset(a,0,sizeof(a));
	si(n);
	FORN(i,n){
		si(j);
		a[j]++;
	}
	int result=min(a[1],a[2]);
	a[1]-=result;
	a[2]-=result;
	result+=(floor(a[1]/3));
	a[1]%=3;
	result+=((int)(a[2]/3))*2;
	a[2]%=3;
	if(a[2]==2){
		result++;
		a[3]++;
		a[1]++;
		a[2]=0;
	}
	a[3]+=result;
	if(a[1]==1){
		if(a[3]>=1){
			result++;
			a[1]--;
			a[3]--;
			a[4]++;
		}
		else if(a[4]>=2){
			result+=2;
			a[4]-=2;
			a[1]--;
			a[3]+=3;
		}
	}
	else if(a[1]==2){
		if(a[4]>=1){
			result+=2;
			a[4]--;
			a[1]-=2;
			a[3]+=2;
		}
		else if(a[3]>=2){
			result+=2;
			a[1]-=2;
			a[3]+=2;
		}
	}
	else if(a[2]==1){
		if(a[4]>=1){
			result++;
			a[4]--;
			a[2]--;
			a[3]+=2;
		}
		else if(a[3]>=2){
			result+=2;
			a[2]--;
			a[3]-=2;
			a[4]+=2;
		}
	}
	cout << (a[1]+a[2] ? -1 : result) << endl;
	return 0;
}


						/*////////////////////////////////////////////////*/
						/* 				 code by d@rk$(@!e   			  */
						/*////////////////////////////////////////////////*/
#include <algorithm>
#include <assert.h>
#include <fstream>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#include <cctype>
#include <climits>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <cstring>

using namespace std;
#define CLR(a) memset(a, 0, sizeof(a))
#define ABS(X) ( (X) > 0 ? (X) : ( -(X) ) )
#define SZ(V) (int )V.size()
#define ALL(V) V.begin(), V.end()
#define RALL(V) V.rbegin(), V.rend()
#define FORN(i, n) for(i = 0; i < n; i++)
#define FORAB(i, a, b) for(i = a; i <= b; i++)
#define si(n) scanf("%d",&n)
#define sll(n) scanf("%lld",&n)
#define ss(s) scanf("%s",s)
#define prin(n) printf("%d\n",n)
#define psi pair < string, int >
#define MOD 1000000007LL
#define PB push_back
#define MP make_pair
#define F first
#define S second

typedef long long LL;
typedef pair<int,int> pii;
typedef pair<double, double> PDD;
typedef pair<LL,LL> pll;
template<class T> string toString(T value){ostringstream sout;sout<<value;return sout.str(); }

int a[1100][1100],w[1100][1100],h[1100][1100];
int v[1100][1100];
int n,m,sum;
pii st;

bool check(int k){
	int ct[2];
	pii x,y;
	queue<pii> q;
	int len=0,vert=0,tt;
	q.push(st);
	v[st.F][st.S]=k;
	ct[0]=ct[1]=0;
	while(!q.empty()){
		x=q.front();
		q.pop();
		tt=0;
		vert++;
		y=x;
		y.F+=k;
		if(y.F<=n && h[y.F][y.S]-h[x.F-1][x.S]==k+1){
			tt++;
			if(v[y.F][y.S]!=k){
				v[y.F][y.S]=k;
				q.push(y);
			}
		}
		y=x;
		y.F-=k;
		if(y.F>=1 && h[x.F][x.S]-h[y.F-1][y.S]==k+1){
			tt++;
			if(v[y.F][y.S]!=k){
				v[y.F][y.S]=k;
				q.push(y);
			}
		}

		y=x;
		y.S+=k;
		if(y.S<=m && w[y.F][y.S]-w[x.F][x.S-1]==k+1){
			tt++;
			if(v[y.F][y.S]!=k){
				v[y.F][y.S]=k;
				q.push(y);
			}
		}
		y=x;
		y.S-=k;
		if(y.S>=1 && w[x.F][x.S]-w[y.F][y.S-1]==k+1){
			tt++;
			if(v[y.F][y.S]!=k){
				v[y.F][y.S]=k;
				q.push(y);
			}
		}
		len+=tt*(k-1);
		ct[tt%2]++;
	}
	if(vert+len/2!=sum || vert==1) return 0;
	return ct[1]==0 || ct[1]==2;
}

int main()
{
	int i,j;
	vector<int> ans;
	si(n);si(m);
	bool flag=true;
	sum=0;
	FORAB(i,1,n){
		FORAB(j,1,m){
			si(a[i][j]);
			sum+=a[i][j];
			if(a[i][j] && flag){
				st=MP(i,j);
				flag=false;
			}
		}
	}
	memset(w,0,sizeof(w));
	memset(h,0,sizeof(h));
	memset(v,0,sizeof(v));
	FORAB(i,1,n) FORAB(j,1,m) w[i][j]=w[i][j-1]+a[i][j];
	FORAB(j,1,m) FORAB(i,1,n) h[i][j]=h[i-1][j]+a[i][j];
	FORAB(i,2,max(n,m)) if(check(i)) ans.PB(i);
	if(!SZ(ans))
		printf("-1\n");
	else
		FORN(i,SZ(ans))
			printf("%d%c",ans[i],(i==SZ(ans)-1 ? '\n' : ' '));
	return 0;
}


						/*////////////////////////////////////////////////*/
						/* 				 code by d@rk$(@!e   			  */
						/*////////////////////////////////////////////////*/
#include <algorithm>
#include <assert.h>
#include <fstream>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#include <cctype>
#include <climits>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <cstring>

using namespace std;
#define CLR(a) memset(a, 0, sizeof(a))
#define ABS(X) ( (X) > 0 ? (X) : ( -(X) ) )
#define SZ(V) (int )V.size()
#define ALL(V) V.begin(), V.end()
#define RALL(V) V.rbegin(), V.rend()
#define FORN(i, n) for(i = 0; i < n; i++)
#define FORAB(i, a, b) for(i = a; i <= b; i++)
#define si(n) scanf("%d",&n)
#define sll(n) scanf("%lld",&n)
#define ss(s) scanf("%s",s)
#define prin(n) printf("%d\n",n)
#define psi pair < string, int >
#define MOD 1000000007LL
#define PB push_back
#define MP make_pair
#define F first
#define S second

typedef long long LL;
typedef pair<int,int> pii;
typedef pair<double, double> PDD;
typedef pair<LL,LL> pll;
template<class T> string toString(T value){ostringstream sout;sout<<value;return sout.str(); }

int main()
{
	int i,j,k,n,a[5];
	memset(a,0,sizeof(a));
	si(n);
	FORN(i,n){
		si(j);
		a[j]++;
	}
	int result=min(a[1],a[2]);
	a[1]-=result;
	a[2]-=result;
	result+=(a[1]/3)*2;
	a[1]%=3;
	result+=(a[2]/3)*2;
	a[2]%=3;
	if(a[2]==2){
		result++;
		a[3]++;
		a[1]++;
		a[2]=0;
	}
	a[3]+=result;
	if(a[1]==1){
		if(a[3]>=1){
			result++;
			a[1]--;
			a[3]--;
			a[4]++;
		}
		else if(a[4]>=2){
			result+=2;
			a[4]-=2;
			a[1]--;
			a[3]+=3;
		}
	}
	else if(a[1]==2){
		if(a[4]>=1){
			result+=2;
			a[4]--;
			a[1]-=2;
			a[3]+=2;
		}
		else if(a[3]>=2){
			result+=2;
			a[1]-=2;
			a[3]+=2;
		}
	}
	else if(a[2]==1){
		if(a[4]>=1){
			result++;
			a[4]--;
			a[2]--;
			a[3]+=2;
		}
		else if(a[3]>=2){
			result+=2;
			a[2]--;
			a[3]-=2;
			a[4]+=2;
		}
	}
	cout << (a[1]+a[2] ? -1 : result) << endl;
	return 0;
}


						/*////////////////////////////////////////////////*/
						/* 				 code by d@rk$(@!e   			  */
						/*////////////////////////////////////////////////*/
#include <algorithm>
#include <assert.h>
#include <fstream>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#include <cctype>
#include <climits>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <cstring>

using namespace std;
#define CLR(a) memset(a, 0, sizeof(a))
#define ABS(X) ( (X) > 0 ? (X) : ( -(X) ) )
#define SZ(V) (int )V.size()
#define ALL(V) V.begin(), V.end()
#define RALL(V) V.rbegin(), V.rend()
#define FORN(i, n) for(i = 0; i < n; i++)
#define FORAB(i, a, b) for(i = a; i <= b; i++)
#define si(n) scanf("%d",&n)
#define ss(s) scanf("%s",s)
#define prin(n) printf("%d\n",n)
#define psi pair < string, int >
#define MOD 1000000007LL
#define PB push_back
#define MP make_pair
#define F first
#define S second

typedef long long LL;
typedef pair<int,int> pii;
typedef pair<double, double> PDD;
typedef pair<LL,LL> pll;
template<class T> string toString(T value){ostringstream sout;sout<<value;return sout.str(); }

int main()
{
	int i,j,k,n,a[5];
	memset(a,0,sizeof(a));
	si(n);
	FORN(i,n){
		si(j);
		a[j]++;
	}
	int result=min(a[1],a[2]);
	a[1]-=result;
	a[2]-=result;
	a[3]+=result;
	result+=(a[1]/3)*2;
	a[3]+=(a[1]/3);
	a[1]%=3;
	result+=((a[2]/3))*2;
	a[3]+=(a[2]/3)*2;
	a[2]%=3;
	if(a[2]==2){
		result++;
		a[3]++;
		a[1]++;
		a[2]=0;
	}
	if(a[1]==1){
		if(a[3]>=1){
			result++;
			a[1]--;
			a[3]--;
			a[4]++;
		}
		else if(a[4]>=2){
			result+=2;
			a[4]-=2;
			a[1]--;
			a[3]+=3;
		}
	}
	else if(a[1]==2){
		if(a[4]>=1){
			result+=2;
			a[4]--;
			a[1]-=2;
			a[3]+=2;
		}
		else if(a[3]>=2){
			result+=2;
			a[1]-=2;
			a[3]+=2;
		}
	}
	else if(a[2]==1){
		if(a[4]>=1){
			result++;
			a[4]--;
			a[2]--;
			a[3]+=2;
		}
		else if(a[3]>=2){
			result+=2;
			a[2]--;
			a[3]-=2;
			a[4]+=2;
		}
	}
	cout << (a[1]+a[2] ? -1 : result) << endl;
	return 0;
}


						/*////////////////////////////////////////////////*/
						/* 				 code by d@rk$(@!e   			  */
						/*////////////////////////////////////////////////*/
#include <algorithm>
#include <assert.h>
#include <fstream>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#include <cctype>
#include <climits>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <cstring>

using namespace std;
#define CLR(a) memset(a, 0, sizeof(a))
#define ABS(X) ( (X) > 0 ? (X) : ( -(X) ) )
#define SZ(V) (int )V.size()
#define ALL(V) V.begin(), V.end()
#define RALL(V) V.rbegin(), V.rend()
#define FORN(i, n) for(i = 0; i < n; i++)
#define FORAB(i, a, b) for(i = a; i <= b; i++)
#define si(n) scanf("%d",&n)
#define ss(s) scanf("%s",s)
#define prin(n) printf("%d\n",n)
#define psi pair < string, int >
#define MOD 1000000007LL
#define PB push_back
#define MP make_pair
#define F first
#define S second

typedef long long LL;
typedef pair<int,int> pii;
typedef pair<double, double> PDD;
typedef pair<LL,LL> pll;
template<class T> string toString(T value){ostringstream sout;sout<<value;return sout.str(); }

int main()
{
	int i,j,k,n,a[5];
	memset(a,0,sizeof(a));
	si(n);
	FORN(i,n){
		si(j);
		a[j]++;
	}
	int result=min(a[1],a[2]);
	a[1]-=result;
	a[2]-=result;
	a[3]+=result;
	result+=(a[1]/3)*2;
	a[3]+=(a[1]/3);
	a[1]%=3;
	result+=((a[2]/3))*2;
	a[3]+=(a[1]/3)*2;
	a[2]%=3;
	if(a[2]==2){
		result++;
		a[3]++;
		a[1]++;
		a[2]=0;
	}
	if(a[1]==1){
		if(a[3]>=1){
			result++;
			a[1]--;
			a[3]--;
			a[4]++;
		}
		else if(a[4]>=2){
			result+=2;
			a[4]-=2;
			a[1]--;
			a[3]+=3;
		}
	}
	else if(a[1]==2){
		if(a[4]>=1){
			result+=2;
			a[4]--;
			a[1]-=2;
			a[3]+=2;
		}
		else if(a[3]>=2){
			result+=2;
			a[1]-=2;
			a[3]+=2;
		}
	}
	else if(a[2]==1){
		if(a[4]>=1){
			result++;
			a[4]--;
			a[2]--;
			a[3]+=2;
		}
		else if(a[3]>=2){
			result+=2;
			a[2]--;
			a[3]-=2;
			a[4]+=2;
		}
	}
	cout << (a[1]+a[2] ? -1 : result) << endl;
	return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;

int a[1000006],pre[1000006],c[5],tc[5],prec[1000006][5];

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);

    for(int N;scanf(" %d",&N)==1;){
        memset(c,0,sizeof(c));
        for(int i=1;i<=N;i++){
            scanf(" %d",&a[i]);
            c[a[i]]++;
        }
        for(int i=0;i<5;i++)
            prec[0][i] = 0;
        sort(a+1,a+N+1);
        pre[0] = 0;
        for(int i=1;i<=N;i++){
            pre[i] = pre[i-1] + a[i];
            for(int j=0;j<5;j++)
                prec[i][j] = prec[i-1][j];
            prec[i][a[i]]++;
        }
        if(pre[N]==0){
            printf("0\n");
            continue;
        }
        if(pre[N]<=2){
            printf("-1\n");
            continue;
        }
        if(c[1]==0 && c[2]==0){
            printf("0\n");
            continue;
        }
        int ans = pre[N];
        for(int i=0;i<=N;i++){
            if(a[i]==0) continue;
            for(int j=0;j<5;j++)
                tc[j] = c[j]-prec[i][j];
            int now = pre[i];
            int need = tc[1]*2 + tc[2];
            int left = now - need;  // now all is 3
            if(left==0){
                ans = min(ans,now);
            }else if(left < 0){
                int still = -left;
                if(tc[4] >= still)
                    ans = min(ans,now+still);
            }else{
                need = tc[1] + tc[2] + tc[3];
                if(left <= need){  // make some to 4
                    ans = min(ans,now);
                }
            }
        }
        printf("%d\n",ans);
    }

    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;

int a[1000006],pre[1000006],c[5],tc[5],prec[1000006][5];

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);

    for(int N;scanf(" %d",&N)==1;){
        memset(c,0,sizeof(c));
        for(int i=1;i<=N;i++){
            scanf(" %d",&a[i]);
            c[a[i]]++;
        }
        for(int i=0;i<5;i++)
            prec[0][i] = 0;
        sort(a+1,a+N+1);
        pre[0] = 0;
        for(int i=1;i<=N;i++){
            pre[i] = pre[i-1] + a[i];
            for(int j=0;j<5;j++)
                prec[i][j] = prec[i-1][j];
            prec[i][a[i]]++;
        }
        if(pre[N]==0){
            printf("0\n");
            continue;
        }
        if(pre[N]<=2){
            printf("-1\n");
            continue;
        }
        if(c[1]==0 && c[2]==0){
            printf("0\n");
            continue;
        }
        int ans = pre[N];
        for(int i=0;i<=N;i++){
            //if(a[i]==0)   continue;
            for(int j=0;j<5;j++)
                tc[j] = c[j]-prec[i][j];
            int now = pre[i];
            int need = tc[1]*2 + tc[2];
            int left = now - need;  // now all is 3
            //printf("i = %d, now = %d, need = %d, left = %d\n",i,now,need,left);
            if(left==0){
                ans = min(ans,now);
            }else if(left < 0){
                int still = -left;
                if(tc[4] >= still)
                    ans = min(ans,now+still);
            }else{
                need = tc[1] + tc[2] + tc[3];
                if(left <= need){  // make some to 4
                    ans = min(ans,now);
                }
            }
        }
        if(ans==pre[N]) ans = -1;
        printf("%d\n",ans);
    }

    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;

int a[1000006],pre[1000006],c[5],tc[5],prec[1000006][5];

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);

    for(int N;scanf(" %d",&N)==1;){
        memset(c,0,sizeof(c));
        for(int i=1;i<=N;i++){
            scanf(" %d",&a[i]);
            c[a[i]]++;
        }
        for(int i=0;i<5;i++)
            prec[0][i] = 0;
        sort(a+1,a+N+1);
        pre[0] = 0;
        for(int i=1;i<=N;i++){
            pre[i] = pre[i-1] + a[i];
            for(int j=0;j<5;j++)
                prec[i][j] = prec[i-1][j];
            prec[i][a[i]]++;
        }
        if(pre[N]==0){
            printf("0\n");
            continue;
        }
        if(pre[N]<=2){
            printf("-1\n");
            continue;
        }
        if(c[1]==0 && c[2]==0){
            printf("0\n");
            continue;
        }
        int ans = pre[N];
        for(int i=0;i<=N;i++){
            //if(a[i]==0)   continue;
            for(int j=0;j<5;j++)
                tc[j] = c[j]-prec[i][j];
            int now = pre[i];
            int need = tc[1]*2 + tc[2];
            int left = now - need;  // now all is 3
            //printf("i = %d, now = %d, need = %d, left = %d\n",i,now,need,left);
            if(left==0){
                ans = min(ans,now);
            }else if(left < 0){
                int still = -left;
                if(tc[4] >= still)
                    ans = min(ans,now+still);
            }else{
                need = tc[1] + tc[2] + tc[3];
                if(left <= need){  // make some to 4
                    ans = min(ans,now);
                }
            }
        }
        printf("%d\n",ans);
    }

    return 0;
}


//Lasha Bukhnikashvili
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<string>
#define Pi 3.14159265358
#define mod9 %1000000009
#define INF 1000000000
#define mod7 1000000007
#define LL  unsigned long long
#define time clock()/(double)CLOCKS_PER_SEC
using namespace std;
 int n,x,i,ans,p[1000001];
int main(){
 #ifndef ONLINE_JUDGE
   freopen("input.txt","r",stdin);
   freopen("output.txt","w",stdout);
 #endif
    cin>>n;
    for (i=1;i<=n;i++)
        cin>>x,p[x]++;
    if (p[1]+p[2]*2+p[3]*3+p[4]*4==1 || p[1]+p[2]*2+p[3]*3+p[4]*4==2 || p[1]+p[2]*2+p[3]*3+p[4]*4==5){cout<<-1; return 0;};
    if (p[1]==p[2]) {cout<<p[1]<<endl; return  0;};
    if (p[1]<p[2]){
       ans+=p[1];
       p[2]-=p[1];
       p[3]+=p[1];
       p[1]=0;
    } else {
      ans+=p[2];
      p[1]-=p[2];
      p[3]+=p[2];
      p[2]=0;
    };
    if (p[1]>0){
       ans+=(p[1]/3)*2;
       p[3]+=(p[1]/3)*2;
       p[1]%=3;
       if (p[1]==0){cout<<ans; return 0;};
       if (p[1]==1){
          if (p[3]>0) {cout<<ans+1; return 0;};
          if (p[4]>1) {cout<<ans+2; return 0;};
          cout<<-1;
          return 0;
       };
       if (p[4]>0) {cout<<ans+2; return 0;};
       if (p[3]>1) {cout<<ans+2; return 0;};
       cout<<-1;
       return 0;
    } else {
      ans+=p[2]/3*2;
      p[2]=p[2]%3;
      if (p[2]==0){cout<<ans; return 0;};
      if (p[2]==1){
         if (p[4]>0) {cout<<ans+1; return 0;};
         if (p[3]>1) {cout<<ans+2; return 0;};
         cout<<-1;
         return 0;
      };
      if (p[2]==2){
         if (p[4]>1){cout<<ans+2; return 0;};
         if (p[4]==1){p[4]=0; ans++; p[2]=1;};
         if (p[2]==1)
            if (p[3]>1){cout<<ans+2; return 0;} else {cout<<-1; return 0;}
         else if (p[3]>3){cout<<ans+4; return 0;} else {cout<<-1; return 0;};

      };
    };
 return 0;
}


//Lasha Bukhnikashvili
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<string>
#define Pi 3.14159265358
#define mod9 %1000000009
#define INF 1000000000
#define mod7 1000000007
#define LL  unsigned long long
#define time clock()/(double)CLOCKS_PER_SEC
using namespace std;
 int n,x,i,ans,p[1000001];
int main(){
 #ifndef ONLINE_JUDGE
   freopen("input.txt","r",stdin);
   freopen("output.txt","w",stdout);
 #endif
    cin>>n;
    for (i=1;i<=n;i++)
        cin>>x,p[x]++;
    if (p[1]+p[2]*2+p[3]*3+p[4]*4==1 || p[1]+p[2]*2+p[3]*3+p[4]*4==2 || p[1]+p[2]*2+p[3]*3+p[4]*4==5){cout<<-1; return 0;};
    if (p[1]==p[2]) {cout<<p[1]<<endl; return  0;};
    if (p[1]<p[2]){
       ans+=p[1];
       p[2]-=p[1];
       p[3]+=p[1];
       p[1]=0;
    } else {
      ans+=p[2];
      p[1]-=p[2];
      p[3]+=p[2];
      p[2]=0;
    };
    if (p[1]>0){
       ans+=(p[1]/3)*2;
       p[3]+=(p[1]/3)*2;
       p[1]%=3;
       if (p[1]==0){cout<<ans; return 0;};
       if (p[1]==1){
          if (p[3]>0) {cout<<ans+1; return 0;};
          if (p[4]>1) {cout<<ans+2; return 0;};
          cout<<-1;
          return 0;
       };
       if (p[4]>0) {cout<<ans+2; return 0;};
       if (p[3]>1) {cout<<ans+2; return 0;};
       cout<<-1;
       return 0;
    } else {
      ans+=p[2]/3*2;
      p[3]+=p[2]/3;
      p[2]=p[2]%3;
      if (p[2]==0){cout<<ans; return 0;};
      if (p[2]==1){
         if (p[4]>0) {cout<<ans+1; return 0;};
         if (p[3]>1) {cout<<ans+2; return 0;};
         cout<<-1;
         return 0;
      };
      if (p[2]==2){
         cout<<ans+2;
         return 0;
      };
    };
 return 0;
}


//Lasha Bukhnikashvili
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<string>
#define Pi 3.14159265358
#define mod9 %1000000009
#define INF 1000000000
#define mod7 1000000007
#define LL  unsigned long long
#define time clock()/(double)CLOCKS_PER_SEC
using namespace std;
 int n,x,i,ans,p[100001];
int main(){
 #ifndef ONLINE_JUDGE
   freopen("input.txt","r",stdin);
   freopen("output.txt","w",stdout);
 #endif
    cin>>n;
    for (i=1;i<=n;i++)
        cin>>x,p[x]++;
    if (p[1]+p[2]*2+p[3]*3+p[4]*4==1 || p[1]+p[2]*2+p[3]*3+p[4]*4==2 || p[1]+p[2]*2+p[3]*3+p[4]*4==5){cout<<-1; return 0;};
    if (p[1]==p[2]) {cout<<p[1]<<endl; return  0;};
    if (p[1]<p[2]){
       ans+=p[1];
       p[2]-=p[1];
       p[3]+=p[1];
       p[1]=0;
    } else {
      ans+=p[2];
      p[1]-=p[2];
      p[3]+=p[2];
      p[2]=0;
    };
    if (p[1]>0){
       ans+=(p[1]/3)*2;
       p[3]+=(p[1]/3)*2;
       p[1]%=3;
       if (p[1]==0){cout<<ans; return 0;};
       if (p[1]==1){
          if (p[3]>0) {cout<<ans+1; return 0;};
          if (p[4]>1) {cout<<ans+2; return 0;};
          cout<<-1;
          return 0;
       };
       if (p[4]>0) {cout<<ans+2; return 0;};
       if (p[3]>1) {cout<<ans+2; return 0;};
       cout<<-1;
       return 0;
    } else {
      ans+=p[2]/3;
      p[2]=p[2]%3;
      if (p[2]==0){cout<<ans; return 0;};
      if (p[2]==1){
         if (p[4]>0) {cout<<ans+2; return 0;};
         if (p[3]>1) {cout<<ans+2; return 0;};
      };
      if (p[2]==2) return -1;
    };
 return 0;
}


//Lasha Bukhnikashvili
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<string>
#define Pi 3.14159265358
#define mod9 %1000000009
#define INF 1000000000
#define mod7 1000000007
#define LL  unsigned long long
#define time clock()/(double)CLOCKS_PER_SEC
using namespace std;
 int n,x,i,ans,p[1000001];
int main(){
 #ifndef ONLINE_JUDGE
   freopen("input.txt","r",stdin);
   freopen("output.txt","w",stdout);
 #endif
    cin>>n;
    for (i=1;i<=n;i++)
        cin>>x,p[x]++;
    if (p[1]+p[2]*2+p[3]*3+p[4]*4==1 || p[1]+p[2]*2+p[3]*3+p[4]*4==2 || p[1]+p[2]*2+p[3]*3+p[4]*4==5){cout<<-1; return 0;};
    if (p[1]==p[2]) {cout<<p[1]<<endl; return  0;};
    if (p[1]<p[2]){
       ans+=p[1];
       p[2]-=p[1];
       p[3]+=p[1];
       p[1]=0;
    } else {
      ans+=p[2];
      p[1]-=p[2];
      p[3]+=p[2];
      p[2]=0;
    };
    if (p[1]>0){
       ans+=(p[1]/3)*2;
       p[3]+=(p[1]/3)*2;
       p[1]%=3;
       if (p[1]==0){cout<<ans; return 0;};
       if (p[1]==1){
          if (p[3]>0) {cout<<ans+1; return 0;};
          if (p[4]>1) {cout<<ans+2; return 0;};
          cout<<-1;
          return 0;
       };
       if (p[4]>0) {cout<<ans+2; return 0;};
       if (p[3]>1) {cout<<ans+2; return 0;};
       cout<<-1;
       return 0;
    } else {
      ans+=p[2]/3*2;
      p[2]=p[2]%3;
      if (p[2]==0){cout<<ans; return 0;};
      if (p[2]==1){
         if (p[4]>0) {cout<<ans+1; return 0;};
         if (p[3]>1) {cout<<ans+2; return 0;};
         cout<<-1;
         return 0;
      };
      if (p[2]==2){
         if (p[4]>1){cout<<ans+2; return 0;};
         if (p[4]==1){p[4]=0; ans++; p[2]=1;};
         if (p[2]==1)
            if (p[3]>1){cout<<ans+2; return 0;} else {cout<<-1; return 0;};
         else if (p[3]>3){cout<<ans+4; return 0;} else {cout<<-1; return 0;};

      };
    };
 return 0;
}


//Lasha Bukhnikashvili
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<string>
#define Pi 3.14159265358
#define mod9 %1000000009
#define INF 1000000000
#define mod7 1000000007
#define LL  unsigned long long
#define time clock()/(double)CLOCKS_PER_SEC
using namespace std;
 int n,x,i,ans,p[100001];
int main(){
 #ifndef ONLINE_JUDGE
   freopen("input.txt","r",stdin);
   freopen("output.txt","w",stdout);
 #endif
    cin>>n;
    for (i=1;i<=n;i++)
        cin>>x,p[x]++;
    if (p[1]+p[2]*2+p[3]*3+p[4]*4==1 || p[1]+p[2]*2+p[3]*3+p[4]*4==2 || p[1]+p[2]*2+p[3]*3+p[4]*4==5){cout<<-1; return 0;};
    if (p[1]==p[2]) {cout<<p[1]<<endl; return  0;};
    if (p[1]<p[2]){
       ans+=p[1];
       p[2]-=p[1];
       p[3]+=p[1];
       p[1]=0;
    } else {
      ans+=p[2];
      p[1]-=p[2];
      p[3]+=p[2];
      p[2]=0;
    };
    if (p[1]>0){
       ans+=(p[1]/3)*2;
       p[3]+=(p[1]/3)*2;
       p[1]%=3;
       if (p[1]==0){cout<<ans; return 0;};
       if (p[1]==1){
          if (p[3]>0) {cout<<ans+1; return 0;};
          if (p[4]>1) {cout<<ans+2; return 0;};
          cout<<-1;
          return 0;
       };
       if (p[4]>0) {cout<<ans+2; return 0;};
       if (p[3]>1) {cout<<ans+2; return 0;};
       cout<<-1;
       return 0;
    } else {
      ans+=p[2]/3;
      p[2]=p[2]%3;
      if (p[2]==0){cout<<ans; return 0;};
      if (p[2]==1){
         if (p[4]>0) {cout<<ans+1; return 0;};
         if (p[3]>1) {cout<<ans+2; return 0;};
      };
      if (p[2]==2) return -1;
    };
 return 0;
}


//Lasha Bukhnikashvili
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<string>
#define Pi 3.14159265358
#define mod9 %1000000009
#define INF 1000000000
#define mod7 1000000007
#define LL  unsigned long long
#define time clock()/(double)CLOCKS_PER_SEC
using namespace std;
 int n,x,i,ans,p[1000001];
int main(){
 #ifndef ONLINE_JUDGE
   freopen("input.txt","r",stdin);
   freopen("output.txt","w",stdout);
 #endif
    cin>>n;
    for (i=1;i<=n;i++)
        cin>>x,p[x]++;
    if (p[1]+p[2]*2+p[3]*3+p[4]*4==1 || p[1]+p[2]*2+p[3]*3+p[4]*4==2 || p[1]+p[2]*2+p[3]*3+p[4]*4==5){cout<<-1; return 0;};
    if (p[1]==p[2]) {cout<<p[1]<<endl; return  0;};
    if (p[1]<p[2]){
       ans+=p[1];
       p[2]-=p[1];
       p[3]+=p[1];
       p[1]=0;
    } else {
      ans+=p[2];
      p[1]-=p[2];
      p[3]+=p[2];
      p[2]=0;
    };
    if (p[1]>0){
       ans+=(p[1]/3)*2;
       p[3]+=(p[1]/3)*2;
       p[1]%=3;
       if (p[1]==0){cout<<ans; return 0;};
       if (p[1]==1){
          if (p[3]>0) {cout<<ans+1; return 0;};
          if (p[4]>1) {cout<<ans+2; return 0;};
          cout<<-1;
          return 0;
       };
       if (p[4]>0) {cout<<ans+2; return 0;};
       if (p[3]>1) {cout<<ans+2; return 0;};
       cout<<-1;
       return 0;
    } else {
      ans+=p[2]/3*2;
      p[3]+=2*(p[2]/3);
      p[2]=p[2]%3;
      if (p[2]==0){cout<<ans; return 0;};
      if (p[2]==1){
         if (p[4]>0) {cout<<ans+1; return 0;};
         if (p[3]>1) {cout<<ans+2; return 0;};
         cout<<-1;
         return 0;
      };
      if (p[2]==2){
         cout<<ans+2;
         return 0;
      };
    };
 return 0;
}


//Lasha Bukhnikashvili
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<string>
#define Pi 3.14159265358
#define mod9 %1000000009
#define INF 1000000000
#define mod7 1000000007
#define LL  unsigned long long
#define time clock()/(double)CLOCKS_PER_SEC
using namespace std;
 int n,x,i,ans,p[100001];
int main(){
 #ifndef ONLINE_JUDGE
   freopen("input.txt","r",stdin);
   freopen("output.txt","w",stdout);
 #endif
    cin>>n;
    for (i=1;i<=n;i++)
        cin>>x,p[x]++;
    if (p[1]+p[2]*2+p[3]*3+p[4]*4==1 || p[1]+p[2]*2+p[3]*3+p[4]*4==2 || p[1]+p[2]*2+p[3]*3+p[4]*4==5){cout<<-1; return 0;};
    if (p[1]==p[2]) {cout<<p[1]<<endl; return  0;};
    if (p[1]<p[2]){
       ans+=p[1];
       p[2]-=p[1];
       p[3]+=p[1];
       p[1]=0;
    } else {
      ans+=p[2];
      p[1]-=p[2];
      p[3]+=p[2];
      p[2]=0;
    };
    if (p[1]>0){
       ans+=(p[1]/3)*2;
       p[3]+=(p[1]/3)*2;
       p[1]%=3;
       if (p[1]==0){cout<<ans; return 0;};
       if (p[1]==1){
          if (p[3]>0) {cout<<ans+1; return 0;};
          if (p[4]>1) {cout<<ans+2; return 0;};
          cout<<-1;
          return 0;
       };
       if (p[4]>0) {cout<<ans+2; return 0;};
       if (p[3]>1) {cout<<ans+2; return 0;};
       cout<<-1;
       return 0;
    } else {
      ans+=p[2]/3*2;
      p[2]=p[2]%3;
      if (p[2]==0){cout<<ans; return 0;};
      if (p[2]==1){
         if (p[4]>0) {cout<<ans+1; return 0;};
         if (p[3]>1) {cout<<ans+2; return 0;};
      };
      if (p[2]==2) return -1;
    };
 return 0;
}


//Lasha Bukhnikashvili
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<string>
#define Pi 3.14159265358
#define mod9 %1000000009
#define INF 1000000000
#define mod7 1000000007
#define LL  unsigned long long
#define time clock()/(double)CLOCKS_PER_SEC
using namespace std;
 int n,x,i,ans,p[100001];
int main(){
 #ifndef ONLINE_JUDGE
   freopen("input.txt","r",stdin);
   freopen("output.txt","w",stdout);
 #endif
    cin>>n;
    for (i=1;i<=n;i++)
        cin>>x,p[x]++;
    if (p[1]+p[2]*2+p[3]*3+p[4]*4==1 || p[1]+p[2]*2+p[3]*3+p[4]*4==2 || p[1]+p[2]*2+p[3]*3+p[4]*4==5){cout<<-1; return 0;};
    if (p[1]==p[2]) {cout<<p[1]<<endl; return  0;};
    if (p[1]<p[2]){
       ans+=p[1];
       p[2]-=p[1];
       p[3]+=p[1];
       p[1]=0;
    } else {
      ans+=p[2];
      p[1]-=p[2];
      p[3]+=p[2];
      p[2]=0;
    };
    if (p[1]>0){
       ans+=(p[1]/3)*2;
       p[3]+=(p[1]/3)*2;
       p[1]%=3;
       if (p[1]==0){cout<<ans; return 0;};
       if (p[1]==1){
          if (p[3]>0) {cout<<ans+1; return 0;};
          if (p[4]>1) {cout<<ans+2; return 0;};
          cout<<-1;
          return 0;
       };
       if (p[4]>0) {cout<<ans+1; return 0;};
       if (p[3]>1) {cout<<ans+2; return 0;};
       cout<<-1;
       return 0;
    } else {
      ans+=p[2]/3;
      p[2]=p[2]%3;
      if (p[2]==0){cout<<ans; return 0;};
      if (p[2]==1){
         if (p[4]>0) {cout<<ans+1; return 0;};
         if (p[3]>1) {cout<<ans+2; return 0;};
      };
      if (p[2]==2) return -1;
    };
 return 0;
}


//Lasha Bukhnikashvili
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<string>
#define Pi 3.14159265358
#define mod9 %1000000009
#define INF 1000000000
#define mod7 1000000007
#define LL  unsigned long long
#define time clock()/(double)CLOCKS_PER_SEC
using namespace std;
 int n,x,i,ans,p[1000001];
int main(){
 #ifndef ONLINE_JUDGE
   freopen("input.txt","r",stdin);
   freopen("output.txt","w",stdout);
 #endif
    cin>>n;
    for (i=1;i<=n;i++)
        cin>>x,p[x]++;
    if (p[1]+p[2]*2+p[3]*3+p[4]*4==1 || p[1]+p[2]*2+p[3]*3+p[4]*4==2 || p[1]+p[2]*2+p[3]*3+p[4]*4==5){cout<<-1; return 0;};
    if (p[1]==p[2]) {cout<<p[1]<<endl; return  0;};
    if (p[1]<p[2]){
       ans+=p[1];
       p[2]-=p[1];
       p[3]+=p[1];
       p[1]=0;
    } else {
      ans+=p[2];
      p[1]-=p[2];
      p[3]+=p[2];
      p[2]=0;
    };
    if (p[1]>0){
       ans+=(p[1]/3)*2;
       p[3]+=(p[1]/3)*2;
       p[1]%=3;
       if (p[1]==0){cout<<ans; return 0;};
       if (p[1]==1){
          if (p[3]>0) {cout<<ans+1; return 0;};
          if (p[4]>1) {cout<<ans+2; return 0;};
          cout<<-1;
          return 0;
       };
       if (p[4]>0) {cout<<ans+2; return 0;};
       if (p[3]>1) {cout<<ans+2; return 0;};
       cout<<-1;
       return 0;
    } else {
      ans+=p[2]/3*2;
      p[2]=p[2]%3;
      if (p[2]==0){cout<<ans; return 0;};
      if (p[2]==1){
         if (p[4]>0) {cout<<ans+1; return 0;};
         if (p[3]>1) {cout<<ans+2; return 0;};
         cout<<-1;
         return 0;
      };
      if (p[2]==2){
         cout<<ans+2;
         return 0;
      };
    };
 return 0;
}


#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <cassert>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define chmax(a,b) (a<(b)?(a=b,1):0)
#define chmin(a,b) (a>(b)?(a=b,1):0)
#define valid(y,x,h,w) (0<=y&&y<h&&0<=x&&x<w)
const int INF = 1<<29;
const double EPS = 1e-8;
const double PI = acos(-1);
typedef pair<int,int> pii;
typedef long long ll;

int t[4];

int main() {
  int n;
  while(cin >> n) {
    int num[4] = {};
    int sum = 0;
    REP(i,n) {
      int x;
      scanf("%d", &x);
      sum += x;
      num[x-1]++;
    }
    int ans = INF;
    for (int n3=0; n3<=sum/3; ++n3) {
      if ((sum-n3*3)%4) continue;
      int n4 = (sum-n3*3)/4;
      int tmp = 0;
      REP(i,4) t[i] = num[i];
      if (t[2] > n3) {
        int r3 = t[2] - n3;
        int d = min(t[0],r3);
        tmp += d;
        t[0] -= d;
        r3 -= d;
        if (r3) {
          int d = min(t[1], r3/2);
          tmp += d*2;
          t[1]-=d;
          r3-=d*2;
          if (r3) {
            tmp += r3/4*3;
          } else {
            tmp += t[1]/2*2;
          }
        } else {
          int d = min(t[1], t[0]/2);
          tmp += d*2;
          t[0] -= d*2;
          t[1] -= d;
          if (t[0]) {
            tmp += t[0]/4*3;
          } else {
            tmp += t[1]/2*2;
          }
        }
      } else if (t[3] > n4) {
        int r4 = t[3] - n4;
        int d = min(r4, t[1]);
        tmp += d;
        t[1] -= d;
        r4 -= d;
        if (r4) {
          assert((r4+t[0])%3 == 0);
          tmp += (r4 + t[0]) / 3 * 2;
        } else {
          int d = min(t[1],t[0]);
          t[1]-=d;
          t[0]-=d;
          tmp+=d;
          if (t[1]) {
            tmp += t[1]/3*2;
          } else {
            tmp += t[0]/3*2;
          }
        }
      } else {
        int k3 = n3 - t[2];
        int k4 = n4 - t[3];
        int d = min(k3+k4, t[1]);
        tmp += k3*2+k4*3-d;
      }
      cout << n3 << " " << n4 << " " << tmp << endl;
      chmin(ans, tmp);
    }
    if (ans == INF) cout << -1 << endl;
    else cout << ans << endl;
  }
}


#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define chmax(a,b) (a<(b)?(a=b,1):0)
#define chmin(a,b) (a>(b)?(a=b,1):0)
#define valid(y,x,h,w) (0<=y&&y<h&&0<=x&&x<w)
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

int reduce(int &x, int &y) {
  int t = min(x,y);
  x-=t;
  y-=t;
  return t;
}

int main() {
  int n;
  while(cin >> n) {
    int a[5] = {};
    REP(i,n) {
      int x;
      scanf("%d",&x);
      a[x]++;
    }
    int ans = 0;
    int t;
    t = reduce(a[1],a[2]); ans += t; a[3] += t;
    t = reduce(a[1],a[3]); ans += t; a[4] += t;
    t = min(a[1]/2,a[4]); a[1] -= t*2; a[4] -= t; ans += t*2; a[3] += t;
    t = reduce(a[2],a[4]); ans += t; a[3] += t*2;
    t = min(a[2],a[3]/2); a[2] -= t; a[3] -= t*2; ans += t*2; a[4] += t*2;
    while(a[1]>0&&a[1]%3) {
      a[1] -= 4;
      ans += 3;
    }
    ans += a[1]/3*2;
    while(a[2]>0&&a[2]%3) {
      a[2] -= 2;
      ans += 2;
    }
    ans += a[2]/3*2;
    if (a[1]<0 || a[2]<0) cout << -1 << endl;
    else cout << ans << endl;
  }
}


#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define chmax(a,b) (a<(b)?(a=b,1):0)
#define chmin(a,b) (a>(b)?(a=b,1):0)
#define valid(y,x,h,w) (0<=y&&y<h&&0<=x&&x<w)
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

int reduce(int &x, int &y) {
  int t = min(x,y);
  x-=t;
  y-=t;
  return t;
}

int main() {
  int n;
  while(cin >> n) {
    int a[5] = {};
    REP(i,n) {
      int x;
      scanf("%d",&x);
      a[x]++;
    }
    int ans = 0;
    int t;
    t = reduce(a[1],a[2]); ans += t; a[3] += t;
    t = reduce(a[1],a[3]); ans += t; a[4] += t;
    t = min(a[1]/2,a[4]); a[1] -= t*2; a[4] -= t; ans += t*2; a[3] += t;
    t = reduce(a[2],a[4]); ans += t; a[3] += t*2;
    t = min(a[2],a[3]/2); a[2] -= t; a[3] -= t*2; ans += t*2; a[4] += t*2;
    if (a[1] || a[2]) cout << -1 << endl;
    else cout << ans << endl;
  }
}


#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <cassert>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define chmax(a,b) (a<(b)?(a=b,1):0)
#define chmin(a,b) (a>(b)?(a=b,1):0)
#define valid(y,x,h,w) (0<=y&&y<h&&0<=x&&x<w)
const int INF = 1<<29;
const double EPS = 1e-8;
const double PI = acos(-1);
typedef pair<int,int> pii;
typedef long long ll;

int t[4];

int main() {
  int n;
  while(cin >> n) {
    int num[4] = {};
    int sum = 0;
    REP(i,n) {
      int x;
      scanf("%d", &x);
      sum += x;
      num[x-1]++;
    }
    int ans = INF;
    for (int n3=0; n3<=sum/3; ++n3) {
      if ((sum-n3*3)%4) continue;
      int n4 = (sum-n3*3)/4;
      int tmp = 0;
      REP(i,4) t[i] = num[i];
      if (t[2] > n3) {
        int r3 = t[2] - n3;
        int d = min(t[0],r3);
        tmp += d;
        t[0] -= d;
        r3 -= d;
        if (r3) {
          int d = min(t[1], r3/2);
          tmp += d*2;
          t[1]-=d;
          r3-=d*2;
          if (r3) {
            tmp += r3/4*3;
          } else {
            tmp += t[1]/2*2;
          }
        } else {
          int d = min(t[1], t[0]/2);
          tmp += d*2;
          t[0] -= d*2;
          t[1] -= d;
          if (t[0]) {
            tmp += t[0]/4*3;
          } else {
            tmp += t[1]/2*2;
          }
        }
      } else if (t[3] > n4) {
        int r4 = t[3] - n4;
        int d = min(r4, t[1]);
        tmp += d;
        t[1] -= d;
        r4 -= d;
        if (r4) {
          assert((r4+t[0])%3 == 0);
          tmp += (r4 + t[0]) / 3 * 2;
        } else {
          int d = min(t[1],t[0]);
          t[1]-=d;
          t[0]-=d;
          tmp+=d;
          if (t[1]) {
            tmp += t[1]/3*2;
          } else {
            tmp += t[0]/3*2;
          }
        }
      } else {
        int k3 = n3 - t[2];
        int k4 = n4 - t[3];
        int d = min(k3+k4, t[1]);
        tmp += k3*2+k4*3-d;
      }
      // cout << n3 << " " << n4 << " " << tmp << endl;
      chmin(ans, tmp);
    }
    if (ans == INF) cout << -1 << endl;
    else cout << ans << endl;
  }
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;

int main()
{
    int n;
    int a[10];
    while(cin >> n)
    {
        memset(a,0,sizeof(a));
        int sum=0;
        for(int i=1; i<=n; i++)
        {
            int x;
            cin >> x;
            a[x]++;
            sum+=x;
        }
        int x, y, flag=0;
        for(x=0; 3*x<=sum; x++)
        {
            if((sum-3*x)%4==0)
            {
                y=(sum-3*x)/4;
                if(x+y<=n)
                {
                    flag=1;
                    break;
                }
            }
        }
        if(!flag) puts("-1");
        else
        {
            int ans=0;
            if(a[1]>=a[2])
            {
                ans+=a[2];
                a[1]-=a[2];
                a[3]+=a[2];
                ans+=a[1]/3*2;
                a[1]%=3;
                if(a[1]==1)
                {
                    if(a[3]) ans++;
                    else  ans+=2;
                }
                else ans+=2;
            }
            else
            {
                ans+=a[1];
                a[2]-=a[1];
                ans+=a[2]/3*2;
                a[2]%=3;
                if(a[2]==2) ans+=2;
                else if(a[2]==1)
                {
                    if(a[4]) ans+=1;
                    else ans+=2;
                }
            }
            cout << ans <<endl;
        }
    }
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;

int main()
{
    int n;
    int a[10];
    while(cin >> n)
    {
        memset(a,0,sizeof(a));
        int sum=0;
        for(int i=1; i<=n; i++)
        {
            int x;
            cin >> x;
            a[x]++;
            sum+=x;
        }
        int x, y, flag=0;
        for(x=0; 3*x<=sum; x++)
        {
            if((sum-3*x)%4==0)
            {
                y=(sum-3*x)/4;
                if(x+y<=n)
                {
                    flag=1;
                    break;
                }
            }
        }
        if(!flag) puts("-1");
        else
        {
            int ans=0;
            if(a[1]>=a[2])
            {
                ans+=a[2];
                a[1]-=a[2];
                a[3]+=a[2];
                ans+=a[1]/3*2;
                a[3]+=a[1]/3;
                a[1]%=3;
                if(a[1]==1)
                {
                    if(a[3]) ans++;
                    else  ans+=2;
                }
                else if(a[1]==2)ans+=2;
            }
            else
            {
                ans+=a[1];
                a[2]-=a[1];
                ans+=a[2]/3*2;
                a[2]%=3;
                if(a[2]==2) ans+=2;
                else if(a[2]==1)
                {
                    if(a[4]) ans+=1;
                    else ans+=2;
                }
            }
            cout << ans <<endl;
        }
    }
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;

int main()
{
    int n;
    int a[10];
    while(cin >> n)
    {
        memset(a,0,sizeof(a));
        int sum=0;
        for(int i=1; i<=n; i++)
        {
            int x;
            cin >> x;
            a[x]++;
            sum+=x;
        }
        int x, y, flag=0;
        for(x=0; 3*x<=sum; x++)
        {
            if((sum-3*x)%4==0)
            {
                y=(sum-3*x)/4;
                if(x+y<=n)
                {
                    flag=1;
                    break;
                }
            }
        }
        if(!flag) puts("-1");
        else
        {
            int ans=0;
            if(a[1]>=a[2])
            {
                ans+=a[2];
                a[1]-=a[2];
                a[3]+=a[2];
                ans+=a[1]/3*2;
                a[1]%=3;
                if(a[1]==1)
                {
                    if(a[3]) ans++;
                    else  ans+=2;
                }
                if(a[1]==2)
                {
                    if(a[4]) ans++;
                    else ans+=2;
                }
            }
            else
            {
                ans+=a[1];
                a[2]-=a[1];
                ans+=a[2]/3*2;
                a[2]%=3;
                if(a[2]==2) ans+=2;
                else if(a[2]==1)
                {
                    if(a[4]) ans+=1;
                    else ans+=2;
                }
            }
            cout << ans <<endl;
        }
    }
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;

int main()
{
    int n;
    int a[10];
    while(cin >> n)
    {
        memset(a,0,sizeof(a));
        for(int i=1; i<=n; i++)
        {
            int x;
            cin >> x;
            a[x]++;
        }
        while(a[1]+a[4]<a[2])
        {
            a[1]+=2;
            a[2]--;
        }
        int ans=0;
        if(a[1]>=a[2])
        {
            ans=a[1];
        }
        else
        {
            ans=a[2];
        }
        cout << ans <<endl;
    }
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;

int main()
{
    int n;
    int a[10];
    while(cin >> n)
    {
        memset(a,0,sizeof(a));
        int sum=0;
        for(int i=1; i<=n; i++)
        {
            int x;
            cin >> x;
            a[x]++;
            sum+=x;
        }
        int x, y, flag=0;
        for(x=0; 3*x<=sum; x++)
        {
            if((sum-3*x)%4==0)
            {
                y=(sum-3*x)/4;
                if(x+y<=n)
                {
                    flag=1;
                    break;
                }
            }
        }
        if(!flag) puts("-1");
        else
        {
            int ans=0;
            if(a[1]>=a[2])
            {
                ans+=a[2];
                a[1]-=a[2];
                ans+=(a[1]/3*2+a[1]%3);
            }
            else
            {
                ans+=a[1];
                a[2]-=a[1];
                ans+=a[2]/3*2;
                a[2]%=3;
                if(a[2]==2) ans+=2;
                else if(a[2]==1)
                {
                    if(a[4]) ans+=1;
                    else ans+=2;
                }
            }
            cout << ans <<endl;
        }
    }
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;

int main()
{
    int n;
    int a[10];
    while(cin >> n)
    {
        memset(a,0,sizeof(a));
        for(int i=1; i<=n; i++)
        {
            int x;
            cin >> x;
            a[x]++;
        }
        while(a[1]+a[4]<a[2])
        {
            a[1]+=2;
            a[2]--;
        }
     //   cout << a[1] <<endl;
        int ans=0;
        if(a[1]>=a[2])
        {
            ans=a[2]+(a[1]-a[2])/3*2+(a[1]-a[2])%3;
        }
        else
        {
            ans=a[2];
        }
        cout << ans <<endl;
    }
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;

int main()
{
    int n;
    int a[10];
    while(cin >> n)
    {
        memset(a,0,sizeof(a));
        for(int i=1; i<=n; i++)
        {
            int x;
            cin >> x;
            a[x]++;
        }
        int ans=1e9;
        while(a[1]<a[2])
        {
            a[1]+=2;
            a[2]-1;
            int tp=a[2]+(a[1]-a[2])/3*2+(a[1]-a[2])%3;
            ans=min(tp,a[2]);
        }
        if(a[1]>=a[2])
        {
            ans=min(ans,a[2]+(a[1]-a[2])/3*2+(a[1]-a[2])%3);
        }
        cout << ans <<endl;
    }
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;

int main()
{
    int n;
    int a[10];
    while(cin >> n)
    {
        memset(a,0,sizeof(a));
        for(int i=1; i<=n; i++)
        {
            int x;
            cin >> x;
            a[x]++;
        }
        int ans=0;
        while(a[1]<a[2])
        {
            a[1]+=2;
            a[2]-1;
            int tp=a[2]+(a[1]-a[2])/3*2+(a[1]-a[2])%3;
            ans=min(tp,a[2]);
        }
    //    minn=a[2]+(a[1]-a[2])/3*2+(a[1]-a[2])%3;
        cout << ans <<endl;
    }
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;

int main()
{
    int n;
    int a[10];
    while(cin >> n)
    {
        memset(a,0,sizeof(a));
        for(int i=1; i<=n; i++)
        {
            int x;
            cin >> x;
            a[x]++;
        }
        int ans=0;
        while(a[1]<a[2])
        {
            int tp=a[2]+(a[1]-a[2])/3*2+(a[1]-a[2])%3;
            ans=min(tp,a[2]);
        }
    //    minn=a[2]+(a[1]-a[2])/3*2+(a[1]-a[2])%3;
        cout << ans <<endl;
    }
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;

int main()
{
    int n;
    int a[10];
    while(cin >> n)
    {
        memset(a,0,sizeof(a));
        for(int i=1; i<=n; i++)
        {
            int x;
            cin >> x;
            a[x]++;
        }
        while(a[1]+a[4]<a[2])
        {
            a[1]+=2;
            a[2]--;
        }
     //   cout << a[1] <<endl;
        int ans=0;
        if(a[1]>=a[2])
        {
            ans=a[2]+(a[1]-a[2])/3*2+(a[1]-a[2])%3;
        }
        else
        {
            ans=a[2];
        }
        cout << ans <<endl;
        int minn=0;
        while(a[1]<a[2])
        {
            a[1]+=2;
            a[2]--;
        }
        minn=a[2]+(a[1]-a[2])/3*2+(a[1]-a[2])%3;
        cout << min(minn,ans) <<endl;
    }
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;

int main()
{
    int n;
    int a[10];
    while(cin >> n)
    {
        memset(a,0,sizeof(a));
        for(int i=1; i<=n; i++)
        {
            int x;
            cin >> x;
            a[x]++;
        }
        while(a[1]+a[4]<a[2])
        {
            a[1]+=2;
            a[2]--;
        }
     //   cout << a[1] <<endl;
        int ans=0;
        if(a[1]>=a[2])
        {
            ans=a[2]+(a[1]-a[2])/3*2+(a[1]-a[2])%3;
        }
        else
        {
            ans=a[2];
        }
      //  cout << ans <<endl;
        int minn=0;
        while(a[1]<a[2])
        {
            a[1]+=2;
            a[2]--;
        }
        minn=a[2]+(a[1]-a[2])/3*2+(a[1]-a[2])%3;
        cout << min(minn,ans) <<endl;
    }
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;

int main()
{
    int n;
    int a[10];
    while(cin >> n)
    {
        memset(a,0,sizeof(a));
        int sum=0;
        for(int i=1; i<=n; i++)
        {
            int x;
            cin >> x;
            a[x]++;
            sum+=x;
        }
        int x, y, flag=0;
        for(x=0; 3*x<=sum; x++)
        {
            if((sum-3*x)%4==0)
            {
                y=(sum-3*x)/4;
                if(x+y<=n)
                {
                    flag=1;
                    break;
                }
            }
        }
        if(!flag) puts("-1");
        else
        {
            int ans=0;
            if(a[1]>=a[2])
            {
                ans+=a[2];
                a[1]-=a[2];
                a[3]+=a[2];
                ans+=a[1]/3*2;
                a[1]%=3;
                if(a[1]==1)
                {
                    if(a[3]) ans++;
                    else  ans+=2;
                }
                if(a[1]==2)
                {
                    if(a[3]) ans++;
                    else ans+=2;
                }
            }
            else
            {
                ans+=a[1];
                a[2]-=a[1];
                ans+=a[2]/3*2;
                a[2]%=3;
                if(a[2]==2) ans+=2;
                else if(a[2]==1)
                {
                    if(a[4]) ans+=1;
                    else ans+=2;
                }
            }
            cout << ans <<endl;
        }
    }
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;

int main()
{
    int n;
    int a[10];
    while(cin >> n)
    {
        memset(a,0,sizeof(a));
        int sum=0;
        for(int i=1; i<=n; i++)
        {
            int x;
            cin >> x;
            a[x]++;
            sum+=x;
        }
        int x, y, flag=0;
        for(x=0; 3*x<=sum; x++)
        {
            if((sum-3*x)%4==0)
            {
                y=(sum-3*x)/4;
                if(x+y<=n)
                {
                    flag=1;
                    break;
                }
            }
        }
        if(!flag) puts("-1");
        else
        {
            int ans=0;
            if(a[1]>=a[2])
            {
                ans+=a[2];
                a[1]-=a[2];
                a[3]+=a[2];
                ans+=a[1]/3*2;
                a[1]%=3;
                if(a[1]==1)
                {
                    if(a[3]) ans++;
                    else  ans+=2;
                }
                else if(a[1]==2)ans+=2;
            }
            else
            {
                ans+=a[1];
                a[2]-=a[1];
                ans+=a[2]/3*2;
                a[2]%=3;
                if(a[2]==2) ans+=2;
                else if(a[2]==1)
                {
                    if(a[4]) ans+=1;
                    else ans+=2;
                }
            }
            cout << ans <<endl;
        }
    }
}


#include <cstdio>
#include <algorithm>

using namespace std;

int n;
int a[5];
const int inf = 0x7fffffff;

int go1() {
    int ret = inf;
    for (int i = 0; i <= a[1]; ++i) {
        int j = a[1] - i;
        if (i > 2 * j && i - 2 * j <= a[3]) {
            ret = min(ret, i);
        } else if (i <= 2 * j && 2 * j - i <= a[4]) {
            ret = min(ret, 2 * j);
        }
    }
    return ret == inf ? -1 : ret;
}

int go2() {
    int ret = inf;
    for (int i = 0; i <= a[2]; ++i) {
        int j = a[2] - i;
        if (2 * i > j && 2 * i - j <= a[3]) {
            ret = min(ret, 2 * i);
        } else if (2 * i <= j && j - 2 * i <= a[4]) {
            ret = min(ret, j);
        }
    }
    return ret == inf ? -1 : ret;
}

int main() {
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        int t;
        scanf("%d", &t);
        a[t]++;
    }
    int sol = 0;
    int tmp = min(a[1], a[2]);
    a[1] -= tmp;
    a[2] -= tmp;
    a[3] += tmp;
    sol += tmp;

    int r = 0;
    if (a[1]) {
        r = go1();
    } else if (a[2]) {
        r = go2();
    }
    if (r == -1) {
        printf("-1\n");
    } else {
        printf("%d\n", sol + r);
    }

    return 0;
}


#include <cstdio>
#include <algorithm>

using namespace std;

int n;
int a[5];
const int inf = 0x7fffffff;

int go1() {
    int ret = inf;
    for (int i = 0; i <= a[1]; ++i) {
        int j = a[1] - i;
        if (i > 2 * j && i - 2 * j <= a[3] + j) {
            ret = min(ret, i);
        } else if (i <= 2 * j && 2 * j - i <= a[4]) {
            ret = min(ret, 2 * j);
        }
    }
    return ret == inf ? -1 : ret;
}

int go2() {
    int ret = inf;
    for (int i = 0; i <= a[2]; ++i) {
        int j = a[2] - i;
        if (2 * i > j && 2 * i - j <= a[3] + j) {
            ret = min(ret, 2 * i);
        } else if (2 * i <= j && j - 2 * i <= a[4]) {
            ret = min(ret, j);
        }
    }
    return ret == inf ? -1 : ret;
}

int main() {
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        int t;
        scanf("%d", &t);
        a[t]++;
    }
    int sol = 0;
    int tmp = min(a[1], a[2]);
    a[1] -= tmp;
    a[2] -= tmp;
    a[3] += tmp;
    sol += tmp;

    int r = 0;
    if (a[1]) {
        r = go1();
    } else if (a[2]) {
        r = go2();
    }
    if (r == -1) {
        printf("-1\n");
    } else {
        printf("%d\n", sol + r);
    }

    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<vector>
#define inf 0x3f3f3f3f
#define Inf 0x3FFFFFFFFFFFFFFFLL
#define eps 1e-9
#define pi acos(-1.0)
using namespace std;
typedef long long ll;
int a[5];
int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int n;
    while(~scanf("%d",&n))
    {
        memset(a,0,sizeof(a));
        int tmp;
        for(int i=0;i<n;++i)
        {
            scanf("%d",&tmp);
            a[tmp]++;
        }
        int ans=0;
        if(a[1]==a[2])
          ans=a[1];
        else if(a[1]>a[2])
        {
            ans=a[2];
            tmp=a[1]-a[2];
            //tmp2=(a[2]+a[3])-tmp%3;
            if(tmp%3==0)
               ans+=tmp/3*2;
            else
            {
                if(tmp%3==1)
                {
                    if(a[2]+a[3]+tmp/3>=1) ans+=tmp/3*2+1;
                    else if(a[4]>=2) ans+=2;
                    else ans=-1;
                }
                else
                {
                    if(a[2]+a[3]+tmp/3>=2) ans+=tmp/3*2+2;
                    else if(a[4]>=1) ans+=tmp/3*2+2;
                    else ans=-1;
                }
            }
        }
        else
        {
            ans=a[1];
            tmp=a[2]-a[1];
            if(tmp%3==0)
              ans+=tmp/3*2;
            else
            {
                if(tmp%3==1)
                {
                    if(a[4]>=1) ans+=tmp/3*2+1;
                    else if(a[1]+a[3]+tmp/3*2>=1) ans+=tmp/3*2+2;
                    else ans=-1;
                }
                else ans+=tmp/3*2+2;
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<vector>
#define inf 0x3f3f3f3f
#define Inf 0x3FFFFFFFFFFFFFFFLL
#define eps 1e-9
#define pi acos(-1.0)
using namespace std;
typedef long long ll;
int a[5];
int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int n;
    while(~scanf("%d",&n))
    {
        memset(a,0,sizeof(a));
        int tmp;
        for(int i=0;i<n;++i)
        {
            scanf("%d",&tmp);
            a[tmp]++;
        }
        int ans=0;
        if(a[1]==a[2])
          ans=a[1];
        else if(a[1]>a[2])
        {
            ans=a[2];
            tmp=a[1]-a[2];
            //tmp2=(a[2]+a[3])-tmp%3;
            if(tmp%3==0)
               ans+=tmp/3*2;
            else
            {
                if(tmp%3==1)
                {
                    if(a[2]+a[3]+tmp/3*2>=1) ans+=tmp/3*2+1;
                    else if(a[4]>=2) ans+=2;
                    else ans=-1;
                }
                else
                {
                    if(a[2]+a[3]+tmp/3*2>=2) ans+=tmp/3*2+2;
                    else if(a[4]>=1) ans+=tmp/3*2+2;
                    else ans=-1;
                }
            }
        }
        else
        {
            ans=a[1];
            tmp=a[2]-a[1];
            if(tmp%3==0)
              ans+=tmp/3*2;
            else
            {
                if(tmp%3==1)
                {
                    if(a[4]>=1) ans+=tmp/3*2+1;
                    else if(a[1]+a[3]+tmp/3*2>=1) ans+=tmp/3*2+2;
                    else ans=-1;
                }
                else ans+=2;
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<vector>
#define inf 0x3f3f3f3f
#define Inf 0x3FFFFFFFFFFFFFFFLL
#define eps 1e-9
#define pi acos(-1.0)
using namespace std;
typedef long long ll;
int a[5];
int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int n;
    while(~scanf("%d",&n))
    {
        memset(a,0,sizeof(a));
        int tmp;
        for(int i=0;i<n;++i)
        {
            scanf("%d",&tmp);
            a[tmp]++;
        }
        int ans=0;
        if(a[1]==a[2])
          ans=a[1];
        else if(a[1]>a[2])
        {
            ans=a[2];
            tmp=a[1]-a[2];
            if(tmp%3==0)
               ans+=tmp/3*2;
            else
            {
                if(tmp%3==1)
                {
                    if(a[2]+a[3]+tmp/3>=1) ans+=tmp/3*2+1;
                    else if(a[4]>=2) ans+=2;
                    else ans=-1;
                }
                else
                {
                    if(a[2]+a[3]+tmp/3>=2) ans+=tmp/3*2+2;
                    else if(a[4]>=1) ans+=tmp/3*2+2;
                    else ans=-1;
                }
            }
        }
        else
        {
            ans=a[1];
            tmp=a[2]-a[1];
            if(tmp%3==0)
              ans+=tmp/3*2;
            else
            {
                if(tmp%3==1)
                {
                    if(a[4]>=1) ans+=tmp/3*2+1;
                    else if(a[1]+a[3]+tmp/3*2>=2) ans+=tmp/3*2+2;
                    else ans=-1;
                }
                else ans+=tmp/3*2+2;
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<vector>
#define inf 0x3f3f3f3f
#define Inf 0x3FFFFFFFFFFFFFFFLL
#define eps 1e-9
#define pi acos(-1.0)
using namespace std;
typedef long long ll;
int a[5];
int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int n;
    while(~scanf("%d",&n))
    {
        memset(a,0,sizeof(a));
        int tmp;
        for(int i=0;i<n;++i)
        {
            scanf("%d",&tmp);
            a[tmp]++;
        }
        int ans=0;
        if(a[1]==a[2])
          ans=a[1];
        else if(a[1]>a[2])
        {
            ans=a[2];
            tmp=a[1]-a[2];
            //tmp2=(a[2]+a[3])-tmp%3;
            if(tmp%3==0)
               ans+=tmp/3*2;
            else
            {
                if(tmp%3==1)
                {
                    if(a[2]+a[3]+tmp/3*2>=1) ans+=tmp/3*2+1;
                    else if(a[4]>=2) ans+=2;
                    else ans=-1;
                }
                else
                {
                    if(a[2]+a[3]+tmp/3*2>=2) ans+=tmp/3*2+2;
                    else if(a[4]>=1) ans+=tmp/3*2+2;
                    else ans=-1;
                }
            }
        }
        else
        {
            ans=a[1];
            tmp=a[2]-a[1];
            if(tmp%3==0)
              ans+=tmp/3*2;
            else
            {
                if(tmp%3==1)
                {
                    if(a[4]>=1) ans+=tmp/3*2+1;
                    else if(a[1]+a[3]+tmp/3*2>=1) ans+=tmp/3*2+2;
                    else ans=-1;
                }
                else ans+=tmp/3*2+2;
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}


#include <stdio.h>

using namespace std;

int main(){
    int n;
    scanf("%d", &n);
    int a,b,d;
    a = b = d = 0;
    bool c = false;
    int tmp;
    for(int i = 0; i < n; i++){
        scanf("%d", &tmp);
        if(tmp == 1) a++;
        if(tmp == 2) b++;
        if(tmp == 3) c = true;
        if(tmp == 4) d++;
    }
    int ans = 0;
    if(b >= a){
        ans += a;
        b -= a;
        a = 0;
        c = true;
    }
    else{
        ans += b;
        a -= b;
        b = 0;
        c = true;
    }
    if(a >= 3){
        tmp = a / 3;
        ans += tmp * 2;
        a = a % 3;
        c = true;
    }
    if(b >= 3){
        tmp = b / 3;
        ans += tmp * 2;
        b = b % 3;
        c = true;
    }
    if(a != 0){
        if(a == 1 && c == true) ans += 1;
        else ans += 2;
    }
    if(b != 0) ans += b;
    printf("%d\n", ans);
    return 0;
}


#include <stdio.h>

using namespace std;

int main(){
    int n;
    scanf("%d", &n);
    int a,b,d;
    a = b = d = 0;
    bool c = false;
    int tmp;
    for(int i = 0; i < n; i++){
        scanf("%d", &tmp);
        if(tmp == 1) a++;
        if(tmp == 2) b++;
        if(tmp == 3) c = true;
        if(tmp == 4) d++;
    }
    int ans = 0;
    if(b >= a && a > 0){
        ans += a;
        b -= a;
        a = 0;
        c = true;
    }
    else if( a > b && b > 0){
        ans += b;
        a -= b;
        b = 0;
        c = true;
    }
    if(a >= 3){
        tmp = a / 3;
        ans += tmp * 2;
        a = a % 3;
        c = true;
    }
    if(b >= 3){
        tmp = b / 3;
        ans += tmp * 2;
        b = b % 3;
        c = true;
    }
    if(a != 0){
        if(a == 1 && c == true) ans += 1;
        else ans += 2;
    }
    if(b != 0){
    if  (d > 0) ans += b;
    else ans += 2;
    }
    printf("%d\n", ans);
    return 0;
}


#include <stdio.h>

using namespace std;

int main(){
    int n;
    scanf("%d", &n);
    int a,b,d;
    a = b = d = 0;
    bool c = false;
    int tmp;
    for(int i = 0; i < n; i++){
        scanf("%d", &tmp);
        if(tmp == 1) a++;
        if(tmp == 2) b++;
        if(tmp == 3) c = true;
        if(tmp == 4) d++;
    }
    int ans = 0;
    if(b >= a){
        ans += a;
        b -= a;
        a = 0;
        c = true;
    }
    else{
        ans += b;
        a -= b;
        b = 0;
        c = true;
    }
    if(a >= 3){
        tmp = a / 3;
        ans += tmp * 2;
        a = a % 3;
        c = true;
    }
    if(b >= 3){
        tmp = b / 3;
        ans += tmp * 2;
        b = b % 3;
        c = true;
    }
    if(a != 0){
        if(a == 1 && c == true) ans += 1;
        else ans += 2;
    }
    if(b != 0){
    if  (d > 0) ans += b;
    else ans += 2;
    }
    printf("%d\n", ans);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define MAXM 100010
long long n,m,k;
int num[MAXM];
bool used[MAXM];
int ans,cnt;
signed main() {
    scanf("%lld%lld%lld",&n,&m,&k);
    int nowval;
    for(register int i=1;i<=m;i++) {
        scanf("%lld",&num[i]);
    }
    for(register int i=1;i<=m;i++) {
        if(used[i]) continue;
        used[i]=true;
        int now=cnt;
        for(register int j=i+1;num[j]-now<=((num[i]-now-1)/k+1)*k&&j<=m;j++) {
            used[j]=true;
            cnt++;
        }
        ++cnt;
        ans++;
    }
    cout<<ans;
    return 0;
}


#include<iostream>
using namespace std;
long long a[100001];
int main()
{
	long long n,m,k,s=0,i,j;
	cin>>n>>m>>k;
	for(i=1;i<=m;i++)
		cin>>a[i];
	i=1;
	while(i<=m)
	{
		j=i;
		while((a[j]-i+k)/k==(a[i]-i+k)/k)
			j++;
		i=j;
		s++;
	}
	cout<<s;
}


#include<bits/stdc++.h>
#define int long long
using namespace std;
main()
{
	#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    int n,m,k;
    cin>>n>>m>>k;
    int sp[m];
    for(int i=0;i<m;i++)
    {
    	cin>>sp[i];
    }
    sort(sp,sp+m);
    if(m==1){
    	cout<<1;
    	return 0;
    }
    int del=0;
    int op=0;
    int x=sp[0]/k;
    while(x*k<sp[0])
    	x++;
    int prev=x;
    for(int i=1;i<m;i++)
    {
       int ele=sp[i]-del;
        int x1=ele/k;
        while(x1*k<ele)
    	x1++;
   if(x1==prev)
   {
   	if(i==m-1)
   	op++;
   	continue;
   }
   else
   {
   	del=(i);
   	op++;
   	int xo=(sp[i]-del)/k;
   	while(xo*k<(sp[i]-del))
   	{
   		xo++;
   	}
   	prev=xo;
   	if(i==m-1)
   	op++;
    }
   }

    cout<<op;

	return 0;
}


#include<bits/stdc++.h>
#define int long long
using namespace std;
main()
{
	#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    int n,m,k;  //accepted DCE CODERS
    cin>>n>>m>>k;
    int sp[m];
    for(int i=0;i<m;i++)
    {
    	cin>>sp[i];
    }
    sort(sp,sp+m);
    if(m==1){
    	cout<<1;
    	return 0;
    }
    int del=0;
    int op=0;
    int x=sp[0]/k;
    while(x*k<sp[0])
    	x++;
    int prev=x;
    for(int i=1;i<m;i++)
    {
       int ele=sp[i]-del;
        int x1=ele/k;
        while(x1*k<ele)
    	x1++;
   if(x1==prev)
   {
   	if(i==m-1)
   	op++;
   	continue;
   }
   else
   {
   	del=(i);
   	op++;
   	int xo=(sp[i]-del)/k;
   	while(xo*k<(sp[i]-del))
   	{
   		xo++;
   	}
   	prev=xo;
   	if(i==m-1)
   	op++;
    }
   }

    cout<<op;

	return 0;
}


#include<bits/stdc++.h>
#define int long long
using namespace std;
main()
{
	#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    int n,m,k;
    cin>>n>>m>>k;
    int sp[m];
    for(int i=0;i<m;i++)
    {
    	cin>>sp[i];
    }
    sort(sp,sp+m);
    int del=0;
    int op=0;
    int x=sp[0]/k;
    while(x*k<sp[0])
    	x++;
    int prev=x;
    for(int i=1;i<m;i++)
    {
       int ele=sp[i]-del;
        int x1=ele/k;
        while(x1*k<ele)
    	x1++;
   if(x1==prev)
   {
   	if(i==m-1)
   	op++;
   	continue;
   }
   else
   {
   	del=(i);
   	op++;
   	int xo=(sp[i]-del)/k;
   	while(xo*k<(sp[i]-del))
   	{
   		xo++;
   	}
   	prev=xo;
   	if(i==m-1)
   	op++;
    }
   }

    cout<<op;

	return 0;
}


#include <iostream>
using namespace std;
int main() {
    long long n; int m, k; cin >> n >> m >> k;
    long long p[m]; for (int i = 0; i < m; i++) cin >> p[i], p[i]--;
    long long ans = 0, i = 0;
    while (i < m) {
        ans++;
        int i0 = i;
        long long a = (p[i] - i) / k;
        long long left = i + a * k, right = left + k;
        while (i < m && p[i] - i0 < right) i++;
    }
    cout << ans << endl;
}


#include <cassert>
#include <iostream>
using namespace std;
int main() {
    long long n, m, k; cin >> n >> m >> k;
    long long p[m]; for (int i = 0; i < m; i++) { cin >> p[i]; assert (p[i] > 0); p[i]--; }
    long long ans = 0, i = 0;
    while (i < m) {
        ans++;
        long long a = (p[i] - i) / k;
        long long left = i + a * k, right = left + k;
        while (i < m && p[i] < right) i++;
    }
    cout << ans << endl;
}


#include <iostream>
using namespace std;
int main() {
    long long n; int m, k; cin >> n >> m >> k;
    long long p[m]; for (int i = 0; i < m; i++) cin >> p[i], p[i]--;
    long long ans = 0, i = 0;
    while (i < m) {
        ans++;
        long long a = (p[i] - i) / k;
        long long left = i + a * k, right = left + k;
        while (i < m && p[i] < right) i++;
    }
    cout << ans << endl;
}


#include <cassert>
#include <iostream>
using namespace std;
int main() {
    long long n; int m, k; cin >> n >> m >> k;
    long long p[m]; for (int i = 0; i < m; i++) cin >> p[i], p[i]--;
    long long ans = 0, i = 0;
    while (i < m) {
        ans++;
        assert (p[i] >= 0);
        long long a = (p[i] - i) / k;
        long long left = i + a * k, right = left + k;
        // assert (left <= p[i]);
        // assert (p[i] < right);
        while (i < m && p[i] < right) i++;
        // cerr << i << ' ' << left << ' ' << right << ' ' << a << endl;

    }
    cout << ans << endl;
}


#include <cassert>
#include <iostream>
using namespace std;
int main() {
    long long n; int m, k; cin >> n >> m >> k;
    long long p[m]; for (int i = 0; i < m; i++) cin >> p[i], p[i]--;
    long long ans = 0, i = 0;
    while (i < m) {
        ans++;
        long long a = (p[i] - i) / k;
        long long left = i + a * k, right = left + k;
        // assert (left <= p[i]);
        assert (p[i] < right);
        while (i < m && p[i] < right) i++;
        // cerr << i << ' ' << left << ' ' << right << ' ' << a << endl;

    }
    cout << ans << endl;
}


#include <cassert>
#include <iostream>
using namespace std;
int main() {
    long long n; int m, k; cin >> n >> m >> k;
    long long p[m]; for (int i = 0; i < m; i++) cin >> p[i], p[i]--;
    long long ans = 0, i = 0;
    while (i < m) {
        ans++;
        long long a = (p[i] - i) / k;
        long long left = i + a * k, right = left + k;
        assert (left <= p[i]);
        assert (p[i] < right);
        while (i < m && p[i] < right) i++;
        // cerr << i << ' ' << left << ' ' << right << ' ' << a << endl;

    }
    cout << ans << endl;
}


#include <cassert>
#include <iostream>
using namespace std;
int main() {
    long long n; int m, k; cin >> n >> m >> k;
    long long p[m]; for (int i = 0; i < m; i++) { cin >> p[i]; assert (p[i] > 0); p[i]--; }
    long long ans = 0, i = 0;
    while (i < m) {
        ans++;
        long long a = (p[i] - i) / k;
        long long left = i + a * k, right = left + k;
        // assert (left <= p[i]);
        // assert (p[i] < right);
        while (i < m && p[i] < right) i++;
        // cerr << i << ' ' << left << ' ' << right << ' ' << a << endl;

    }
    cout << ans << endl;
}


#include <cassert>
#include <iostream>
using namespace std;
int main() {
    long long n; int m, k; cin >> n >> m >> k;
    long long p[m]; for (int i = 0; i < m; i++) { cin >> p[i]; p[i]--; assert (p[i] >= 0); }
    long long ans = 0, i = 0;
    while (i < m) {
        ans++;
        long long a = (p[i] - i) / k;
        long long left = i + a * k, right = left + k;
        // assert (left <= p[i]);
        // assert (p[i] < right);
        while (i < m && p[i] < right) i++;
        // cerr << i << ' ' << left << ' ' << right << ' ' << a << endl;

    }
    cout << ans << endl;
}


#include <cassert>
#include <iostream>
using namespace std;
int main() {
    long long n; int m, k; cin >> n >> m >> k;
    long long p[m]; for (int i = 0; i < m; i++) cin >> p[i], p[i]--;
    long long ans = 0, i = 0;
    while (i < m) {
        ans++;
        long long a = (p[i] - i) / k;
        long long left = i + a * k, right = left + k;
        assert (left <= p[i]);
        // assert (p[i] < right);
        while (i < m && p[i] < right) i++;
        // cerr << i << ' ' << left << ' ' << right << ' ' << a << endl;

    }
    cout << ans << endl;
}


#include <cstring>
#include <cstdio>
#include <algorithm>

using namespace std;

long long a[100005];

int main()
{
  long long n;
  int m;
  long long k;
  scanf("%lld%d%lld", &n, &m, &k);
  for (int i = 1; i <= m; i++)
  {
    scanf("%lld", &a[i]);
    a[i]--;
  }
  int i = 1;
  int now = 0;
  int ans = 0;
  while (i <= m)
  {
    long long t = (a[i] - now) / k;
    ans++;
    while ((a[i + 1] - now) / k == t && i < m)
      i++;
    now = i;
    i++;
  }
  printf("%d\n", ans);
  return 0;
}