#include <bits/stdc++.h>
using namespace std;
inline int in() {
  int32_t x;
  scanf("%d", &x);
  return x;
}
inline long long lin() {
  long long x;
  scanf("%lld", &x);
  return x;
}
inline string get() {
  char ch[2000010];
  scanf("%s", ch);
  return ch;
}
const int MAX_LG = 40;
const long long maxn = 1e6 + 10;
const long long base = 29;
const long long mod = 1e9 + 7;
const long long INF = 1e9 + 100;
const long long SQ = 317;
long long Cnt[maxn], a[maxn], tot, res = INF, next_gen[maxn];
pair<long long, long long> where[5];
int32_t main() {
  long long n = in();
  for (long long i = 0; i < n; i++) {
    a[i] = in(), Cnt[a[i]]++;
    tot += a[i];
  }
  sort(a, a + n);
  for (long long i = 0; i < n; i++) {
    long long j = i;
    while (j < n && a[j] == a[i]) j++;
    next_gen[i] = j;
    i = j - 1;
  }
  for (long long three = 0; three * 3 <= tot; three++) {
    long long rem = tot - three * 3;
    if (rem % 4) continue;
    long long four = rem / 4;
    if (four + three > n) continue;
    if (three == 7) {
    }
    long long dif = 0;
    if (four && three) {
      where[4] = {n - four, n - 1};
      where[3] = {n - four - three, n - four - 1};
    } else if (four)
      where[4] = {n - four, n - 1};
    else if (three)
      where[3] = {n - three, n - 1};
    for (long long pt = 0; pt < n; pt = next_gen[pt]) {
      long long threeCnt = 0, fourCnt = 0;
      if (three &&
          min(where[3].second + 1, next_gen[pt]) - max(where[3].first, pt) >= 1)
        threeCnt =
            min(where[3].second + 1, next_gen[pt]) - max(where[3].first, pt);
      if (four &&
          min(where[4].second + 1, next_gen[pt]) - max(where[4].first, pt) >= 1)
        fourCnt =
            min(where[4].second + 1, next_gen[pt]) - max(where[4].first, pt);
      dif += abs(a[pt] - 3) * threeCnt + abs(a[pt] - 4) * fourCnt +
             max(0ll, next_gen[pt] - pt - threeCnt - fourCnt) * a[pt];
    }
    res = min(res, dif / 2);
  }
  cout << (res == INF ? -1 : res) << "\n";
}
