#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

class Graph{
	private:
	int n;
	vvi g;
	public:
	vi match,used;
	bool BM_dfs(int v){
		used[v]=1;
		for(auto u:g[v]){
			int w=match[u];
			if(w<0||!used[w]&&BM_dfs(w)){
				match[v]=u;
				match[u]=v;
				return 1;
			}
		}
		return 0;
	}
	int BM(){
		int res=0;
		match=vi(n,-1);
		for(int i=0;i<n;i++) if(match[i]<0){
			used=vi(n);
			if(BM_dfs(i)) res++;
		}
		return res;
	}
	Graph(int v){
		n=v;
		g=vvi(v);
	}
	void add_edge(int s,int t){
		g[s].push_back(t);
		g[t].push_back(s);
	}
};

int n;
vi a;

int main(){
	cin>>n;
	a=vi(n);
	for(auto &i:a) cin>>i;
	vvi b(2);
	for(int i=0;i<n;i++){
		if(i==0||a[i-1]!=a[i]-1){
			b[a[i]%2].push_back(a[i]);
		}
		if(i==n-1||a[i]!=a[i+1]-1){
			b[(a[i]+1)%2].push_back(a[i]+1);
		}
	}
	int n1=b[0].size(),n2=b[1].size();
	Graph g(n1+n2);
	for(int i=0;i<n1;i++) for(int j=0;j<n2;j++){
		int t=abs(b[0][i]-b[1][j]);
		bool B=1;
		for(int k=2;k*k<=t&&B;k++) if(t%k==0) B=0;
		if(t==1) B=0;
		if(B) g.add_edge(i,n1+j);
	}
	int t=g.BM(),res=t;
	n1-=t;n2-=t;
	res+=n1/2*2+n2/2*2;
	if(n1%2==1) res+=3;
	cout<<res<<endl;
}