#include <bits/stdc++.h>

#define reg register
#define pr std::pair<int, int>
#define fi first
#define se second
#define FIN(s) freopen(s, "r", stdin)
#define FOUT(s) freopen(s, "w", stdout)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define rep(i, l, r) for (int i = l; i <= r; ++i)
#define lep(i, l, r) for (int i = l; i < r; ++i)
#define irep(i, r, l) for (int i = r; i >= l; --i)
#define ilep(i, r, l) for (int i = r; i > l; --i)
#define Rep(i, n) rep(i, 1, n)
#define Lep(i, n) lep(i, 1, n)
#define IRep(i, n) irep(i, n, 1)
#define ILep(i, n) ilep(i, n, 1)
typedef long long ll;
typedef long double ld;

namespace modular {
    const int MOD = 1000000007;
    inline int add(int x, int y) { return (x += y) >= MOD ? x -= MOD : x; }
    inline void inc(int &x, int y) { (x += y) >= MOD ? x -= MOD : 0; }
    inline int mul(int x, int y) { return 1LL * x * y % MOD; }
    inline int qpow(int x, int y) {
        int ans = 1;
        for (; y; y >>= 1, x = mul(x, x))
            if (y & 1)
                ans = mul(ans, x);
        return ans;
    }
}; // namespace modular

namespace Base {
    template <typename Tp> inline Tp input() {
        Tp x = 0, y = 1;
        char c = getchar();
        while ((c < '0' || '9' < c) && c != EOF) {
            if (c == '-')
                y = -1;
            c = getchar();
        }
        if (c == EOF)
            return 0;
        while ('0' <= c && c <= '9')
            x = x * 10 + c - '0', c = getchar();
        return x *= y;
    }
    template <typename Tp> inline void read(Tp &x) { x = input<Tp>(); }
    template <typename Tp> inline void chmax(Tp &x, Tp y) { x < y ? x = y : 0; }
    template <typename Tp> inline void chmin(Tp &x, Tp y) { x > y ? x = y : 0; }
}; // namespace Base
using namespace Base;
/*----------------------------------------------------------------------------*/

#define MAX_N 207
#define MAX_P 10000007

int N, res;
int a[MAX_N], b[MAX_N];
int pri[MAX_P / 10], tot;
int match[MAX_N];
bool check[MAX_P], con[MAX_N][MAX_N], vis[MAX_N];

void sieve(int n) {
    rep(i, 2, n) {
        if (!check[i]) pri[++tot] = i;
        Rep(j, tot) {
            if (i * pri[j] > n) break;
            check[i * pri[j]] = true;
            if (i % pri[j] == 0) break;
        }
    }
    check[2] = check[1] = 1;
}

bool dfs(int x) {
    Rep(j, N) if (con[x][j] && !vis[j]) {
        vis[j] = true;
        if (!match[j] || dfs(match[j])) {
            match[j] = x;
            return true;
        }
    }
    return false;
}

void solve() {
    int top = 0;
    std::sort(a + 1, a + N + 1);
    a[0] = -1, a[N + 1] = 0;
    Rep(i, N) {
        if (a[i - 1] != a[i] - 1) b[++top] = a[i];
        if (a[i] + 1 != a[i + 1]) b[++top] = a[i] + 1;
    }
    N = top;
    Rep(i, N) a[i] = b[i];
    // Rep(i, N) printf("%d ", a[i]); puts("");return;
    Rep(i, N) if (a[i] & 1) {
        Rep(j, N) if (a[j] % 2 == 0 && !check[std::abs(a[i] - a[j])]) con[i][j] = true;
    }
    Rep(i, N) if (a[i] & 1) {
        Rep(j, N) vis[j] = false;
        res += dfs(i);
    }
    Rep(i, N) vis[i] = false;
    Rep(i, N) if (a[i] % 2 == 0 && match[i]) vis[i] = vis[match[i]] = true;
    int cnt[2] = {0};
    Rep(i, N) if (!vis[i]) cnt[a[i] & 1]++;
    res += 2 * (cnt[0] / 2 + cnt[1] / 2);
    if (cnt[0] & 1) res += 3;
    printf("%d\n", res);
}

int main() {
    read(N);
    int mx = 0;
    Rep(i, N) read(a[i]), chmax(mx, a[i]);
    sieve(mx);
    solve();
    return 0;
}


Measured memory_bytes: 12672