#include <bits/stdc++.h>
#define x first
#define y second
#define mp make_pair
#define all(a) a.begin(), a.end()
#define pub push_back
#define ll long long
					  
using namespace std;

int n;
int a[111];
bool prime[10000007];
vector<int> g[222];
int dx[222], dy[222];

bool wasIn(int x){
	for (int i = 0; i < n; i++) if (a[i] == x) return 1;
	return 0;
}

bool check(int x){
	return wasIn(x) != wasIn(x + 1);
}

bool was[222];
bool dfs(int v){
	if (was[v]) return 0;
	was[v] = 1;
	for (int to : g[v]){
		if (dy[to] == -1){
			dx[v] = to;
			dy[to] = v;
			return 1;
		}
		if (dfs(dy[to])){
			dx[v] = to;
			dy[to] = v;
			return 1;
		}
	}
	return 0; 
}

int main(){
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	//freopen("seating.in", "r", stdin);
	//freopen("seating.out", "w", stdout);
	for (int i = 2; i < 10000007; i++){
		if (!prime[i]){	
			for (int j = 2 * i; j < 10000007; j += i) prime[j] = 1;
		}
	}

	prime[2] = 1;
	prime[1] = 1;
	prime[0] = 1;

	cin >> n;
	for (int i = 0; i < n; i++) cin >> a[i];

	vector<int> q, s, t;
	for (int i = 0; i < n; i++){
		if (check(a[i] - 1)) q.pub(a[i] - 1);
		if (check(a[i])) q.pub(a[i]);
	}

	for (int x : q) if (x % 2 == 0) s.pub(x); else t.pub(x);

	for (int i = 0; i < s.size(); i++) for (int j = 0; j < t.size(); j++) if (!prime[abs(s[i] - t[j])]){
		g[i].pub(j);
	}	

	for (int i = 0; i < 222; i++) dx[i] = -1, dy[i] = -1;

	for (int run = 1; run; ){
		run = 0;
		memset(was, 0, sizeof(was));
		for (int i = 0; i < s.size(); i++) if (dx[i] == -1 && dfs(i)) run = 1;
	}

	int dd = 0;

	for (int i = 0; i < s.size(); i++) if (dx[i] != -1) dd++;

	int ans = (int)s.size() + (int)t.size() - dd;

	if (((int)s.size() - dd) % 2 == 1) ans++;

	cout << ans;
}