#include <bits/stdc++.h>
using namespace std;

const int N=1e7+1e2;

template<typename T>inline void read(T &x)
{
	x=0;T c=getchar(),p=1;
	while(!isdigit(c)){if(c=='-')p=-1;c=getchar();}
	while(isdigit(c)){x=(x<<1)+(x<<3)+(c^'0');c=getchar();}
	x*=p;
}

int n;
int P[105];

int cnt,ispri[N],pri[N];

inline void Getprime(int Up)
{
	for(int i=2;i<=Up;i++)ispri[i]=1;
	for(int i=2;i<=Up;i++){
		if(ispri[i])pri[++cnt]=i;
		for(int j=1;j<=cnt && 1ll*i*pri[j]<=Up;j++){
			ispri[i*pri[j]]=0;
			if(i%pri[j]==0)break;
		}
	}
}

inline void File()
{
	freopen("magic.in","r",stdin);
	freopen("magic.out","w",stdout);
}

const int M=2e6+1e2;

bool G[1505][1505];
int tot,tot1,tot2,point,A[1005],B[1005],match[1005],vis[1005];

inline bool Dfs(int x)
{
	for(int i=1;i<=tot2;i++){
		if(!vis[i] && G[x][i]){
			vis[i]=1;
			if(match[i]==-1 || Dfs(match[i])){
				match[i]=x;
				return 1;
			}
		}
	}
	return 0;
}

int main()
{
	//File();
	Getprime(N-10);
	read(n);
	for(int i=1;i<=n;i++)read(P[i]);
	if(P[1]&1)A[++tot1]=P[1];
	else B[++tot2]=P[1];
	for(int i=2;i<=n;i++){
		if(P[i]!=P[i-1]+1){
			if((P[i-1]+1)&1)A[++tot1]=P[i-1]+1;
			else B[++tot2]=P[i-1]+1;
			if(P[i]&1)A[++tot1]=P[i];
			else B[++tot2]=P[i];
		}
	}
	if((P[n]+1)&1)A[++tot1]=P[n]+1;
	else B[++tot2]=P[n]+1;
	for(int i=1;i<=tot1;i++)
		for(int j=1;j<=tot2;j++)
			if(ispri[abs(A[i]-B[j])])G[i][j]=1;
	int Ans=0;
	memset(match,-1,sizeof match);
	for(int i=1;i<=tot1;i++){
		memset(vis,0,sizeof vis);
		if(Dfs(i))Ans++;
	}
	
	Ans=Ans+(tot1-Ans)/2*2+(tot2-Ans)/2*2;
	if((tot1-Ans)&1)Ans+=3;
	printf("%d\n",Ans);
	return 0;
}	
