#include <bits/stdc++.h>   using namespace std;   int cnt[5];   int main() {     int n, t;     cin >> n;     memset(cnt, 0, sizeof(0));     for (int i = 0; i < n; i++) {       cin >> t;       cnt[t]++;     }     bool flag = true;     int ret = 0;     int minN = min(cnt[1], cnt[2]);     cnt[3] += minN;     cnt[1] -= minN;     cnt[2] -= minN;     ret += minN;     if (cnt[1] != 0) {       while (cnt[1] >= 3) {         cnt[3]++;         ret += 2;         cnt[1] -= 3;       }       if (cnt[1] == 1) {         if (cnt[3] > 0) {           cnt[4] + 1;           cnt[3]--;           cnt[1] = 0;           ret += 1;         } else if (cnt[4] >= 2) {           cnt[4] -= 2;           cnt[3] += 3;           cnt[1] = 0;           ret += 2;         } else           flag = false;       } else if (cnt[1] == 2) {         if (cnt[4] > 0) {           cnt[4] -= 1;           cnt[3] += 2;           ret += 2;           cnt[1] = 0;         } else if (cnt[3] >= 2) {           cnt[3] -= 2;           cnt[4] += 2;           cnt[1] = 0;           ret += 2;         } else           flag = false;       }     } else {       while (cnt[2] >= 3) {         cnt[2] -= 3;         ret += 2;         cnt[3] += 2;       }       if (cnt[2] == 1) {         if (cnt[4] > 0) {           cnt[4]--;           cnt[3] += 1;           cnt[2] = 0;           ret++;         } else if (cnt[3] > 1) {           cnt[4] += 2;           cnt[3] -= 2;           cnt[2] = 0;           ret += 2;         } else           flag = false;       } else if (cnt[2] == 2) {         cnt[2] = 0;         cnt[4]++;         ret += 2;       }     }     if (flag)       cout << ret << endl;     else       cout << -1 << endl;     return 0;   }   