#include <bits/stdc++.h>
using namespace std;
const int N = 100 + 5;
int n, x[N], a[N], b[N], an, bn, G[N][N], vis[N], id[N];
map<int, int> M;
int pri(int x) {
	if(x == 1) return 0;
	for(int i = 3; i * i <= x; ++i) if (x % i == 0) return 0;
	return 1;
}
int dfs(int x) {
	for(int i = 1; i <= bn; ++i) if (G[x][i] == 1 && !vis[i]) {
		vis[i] = 1;
		if (!id[i] || dfs(id[i])) {
			id[i] = x;
			return 1;
		}
	}
	return 0;
}
int main() {
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i) scanf("%d", &x[i]), M[x[i]] ^= 1, M[x[i] + 1] ^= 1;
	for(auto x:M) if (x.second) { (x.first & 1 ? a[++an] : b[++bn]) = x.first; }
	for(int i = 1; i <= an; ++i) for(int j = 1; j <= bn; ++j) if (pri(abs(a[i] - b[j]))) G[i][j] = 1;
	int ans = 0;
	for(int i = 1; i <= an; ++i) {
		memset (vis, 0, sizeof vis);
		ans += dfs(i);
	}
	ans += ((an - ans) / 2 + (bn - ans) / 2) * 2 + ((an - ans) & 1) * 3;
	printf ("%d\n", ans);
	return 0;
}




















