#include "math.h"
#include <algorithm>
#include <complex>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
#define ifor(i, a, b) for (int i = (a); i < (b); i++)
#define rfor(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
using namespace std;
typedef long double ld;
typedef long long int lli;
typedef complex<double> P;
const double eps = 1e-11;
int vex[4] = {1, 0, -1, 0};
int vey[4] = {0, 1, 0, -1};
typedef vector<double> Vec;
typedef vector<int> vec;
typedef vector<Vec> MAT;
typedef vector<vec> mat;
lli MOD = 1000000007;
int INF = 100000000;
struct edge {
    int to, cap, rev;
    edge(int to, int cap, int rev)
    {
        this->to = to;
        this->cap = cap;
        this->rev = rev;
    }
};

#define MAX_V 100005
vector<edge> G[MAX_V];
int level[MAX_V];
int iter[MAX_V];
void add_edge(int from, int to, int cap)
{
    G[from].push_back(edge(to, cap, G[to].size()));
    G[to].push_back(edge(from, 0, G[from].size() - 1));
}
lli gcd(lli a, lli b)
{
    return b > a ? gcd(b, a) : (b == 0 ? a : gcd(b, a % b));
}
void bfs(int s)
{
    //memset(level, -1, sizeof(level));
    rep(i, MAX_V) level[i] = -1;
    queue<int> que;
    level[s] = 0;
    que.push(s);
    while (!que.empty()) {
        int v = que.front();
        que.pop();
        for (int i = 0; i < G[v].size(); i++) {
            edge& e = G[v][i];
            if (e.cap > 0 && level[e.to] < 0) {
                level[e.to] = level[v] + 1;
                que.push(e.to);
            }
        }
    }
}
int dfs(int v, int t, int f)
{
    if (v == t)
        return f;
    for (int& i = iter[v]; i < G[v].size(); i++) {
        edge& e = G[v][i];
        if (e.cap > 0 && level[v] < level[e.to]) {
            int d = dfs(e.to, t, min(f, e.cap));
            if (d > 0) {
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}
int max_flow(int s, int t)
{
    int flow = 0;
    while (true) {
        bfs(s);
        if (level[t] < 0)
            return flow;
        //memset(iter, 0, sizeof(iter));
        rep(i, MAX_V) iter[i] = 0;
        int f;
        while ((f = dfs(s, t, INF)) > 0) {
            flow += f;
        }
    }
}
void init()
{
    rep(i, 2005)
    {
        G[i].clear();
        level[i] = 0;
        iter[i] = 0;
    }
}
int main()
{

    int n;
    cin >> n;
    int x[1005];
    rep(i, n) cin >> x[i];
    map<int, int> m;
    rep(i, n)
    {
        m[x[i]] = 1;
    }
    map<int, int> b;
    auto mm = m;
    for (auto s : mm) {
        b[s.first] = s.second ^ m[s.first - 1];
        b[s.first + 1] = s.second ^ m[s.first + 1];
    }

    init();
    vector<int> v_odd, v_even;
    for (auto a : b) {
        if (a.second == 1) {
            if (a.first & 1)
                v_odd.push_back(a.first);
            else
                v_even.push_back(a.first);
            //cout << a.first << endl;
        }
    }
    int sz = v_odd.size() + v_even.size();
    int s = sz;
    int t = sz + 1;
    auto prime = [](lli a) -> bool {
        for (int i = 2; i * i <= a; i++) {
            if (a % i == 0)
                return false;
        }
        return true;
    };
    rep(i, v_odd.size()) add_edge(s, i, 1);
    rep(i, v_even.size()) add_edge(v_odd.size() + i, t, 1);
    rep(i, v_odd.size())
    {
        rep(j, v_even.size())
        {
            int h = abs(v_odd[i] - v_even[j]);
            if (h & 1 and h >= 3 and prime(h)) {
                add_edge(i, v_odd.size() + j, 1);
            }
        }
    }
    lli hoge = max_flow(s, t);
    cout << hoge + ((v_even.size() - hoge) / 2) * 2 + ((v_odd.size() - hoge) / 2) * 2 + ((v_even.size() - hoge) % 2) * 3 << endl;
}


Measured memory_bytes: 3584