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

const int maxn = 220;
const int maxx = 11000000;

int x[maxn];
vector<int> pos;
bool nprm[maxx] = {true, true};
vector<int> g[maxn];
vector<int> x1, x2;
bool vis[maxn];
int link[maxn];

inline bool dfs(int u) {
	if(vis[u]) return false;
	vis[u] = true;
	for(auto v : g[u]) {
		if(link[v] == -1 || dfs(link[v])) {
			link[v] = u;
			link[u] = v;
			return true;
		}
	}
	return false;
}

inline void init() {
	for(int i = 2; i * i < maxx; ++ i) if(!nprm[i])
		for(int j = i + i; j < maxx; j += i) nprm[j] = true;
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	init();
	int n; cin >> n;
	for(int i = 1; i <= n; ++ i) cin >> x[i];
	pos.push_back(x[1]);
	for(int i = 2; i <= n; ++ i) {
		if(x[i] == x[i - 1] + 1) continue;
		pos.push_back(x[i - 1] + 1); pos.push_back(x[i]);
	}
	pos.push_back(x[n] + 1);
	int sz = pos.size();
	for(int i = 0; i < sz; ++ i) if(pos[i] & 1) x1.push_back(i); else x2.push_back(i);
	for(auto i : x1) for(auto j : x2) if(i < j && !nprm[pos[j] - pos[i]] || i > j && !nprm[pos[i] - pos[j]]) g[i].push_back(j);
	memset(link, 0xff, sizeof link);
	int mx = 0;
	for(auto i : x1) {
		memset(vis, false, sizeof vis);
		if(dfs(i)) ++ mx;
	}
	int ans = mx;
	int c1 = (x1.size() - mx) / 2, l1 = (x1.size() - mx) & 1;
	int c2 = (x2.size() - mx) / 2, l2 = (x2.size() - mx) & 1;
	if(l1 && l2) {
		ans += 3;
		l1 = l2 = 0;
	}
	ans += c1 * 2 + l1 * 3;
	ans += c2 * 2 + l2 * 3;
	cout << ans << "\n";
	return 0;
}