#include <bits/stdc++.h>
using namespace std;
const int maxn=105;
int n,a[maxn],cnt[2],match[maxn<<1];
bool used[maxn<<1];
vector<int> G[maxn<<1],diff;
set<int> vis;
bool dfs(int v) {
    used[v]=1;
    for (int i=0;i<(int)G[v].size();++i) {
        int u=G[v][i],w=match[u];
        if (w==-1||(!used[w]&&dfs(w))) {
            match[v]=u;
            match[u]=v;
            return true;
        }
    }
    return false;
}
inline int bipartite_matching() {
    int ret=0;
    memset(match,-1,sizeof match);
    for (int i=0;i<(int)diff.size();++i)
        if (diff[i]%2==1&&match[i]==-1) {
            memset(used,0,sizeof used);
            ret+=dfs(i);
        }
    return ret;
}
bool check(int x) {
    if (x<=2)
        return false;
    for (int i=2;i*i<=x;++i)
        if (x%i==0)
            return false;
    return true;
}
int main()
{
    scanf("%d",&n);
    for (int i=1;i<=n;++i) {
        scanf("%d",&a[i]);
        vis.insert(a[i]);
    }
    for (int i=1;i<=n;++i) {
        if (vis.find(a[i]-1)==vis.end()) {
            diff.push_back(a[i]);
            ++cnt[a[i]%2];
        }
        if (vis.find(a[i]+1)==vis.end()) {
            diff.push_back(a[i]+1);
            ++cnt[(a[i]+1)%2];
        }
    }
    for (int i=0;i<(int)diff.size();++i)
        for (int j=i+1;j<(int)diff.size();++j)
            if (check(abs(diff[i]-diff[j]))) {
                G[i].push_back(j);
                G[j].push_back(i);
            }
    int k=bipartite_matching();
    printf("%d\n",k+2*((cnt[0]-k)/2+(cnt[1]-k)/2)+(cnt[0]-k)%2*3);
    return 0;
}
