// Prime Flip
// * frank_c1
// * 2017 / 12 / 24

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

const int maxn = 205;
const int maxM = (int)(1e7) + 5;
int pr[maxM], chk[maxM];

void gen() {
	int mx = (int)(1e7) + 1, tot = 0;
	chk[1] = 1;
	for (int i = 2; i <= mx; ++i) {
		if (!chk[i]) {
			pr[++tot] = i;
		}
		for (int j = 1; j <= tot; ++j) {
			if (i * pr[j] > mx) break;
			chk[i * pr[j]] = 1;
			if (i % pr[j] == 0) break;
		}
	}
}

int a[maxn], b[maxn], vi[maxn], lk[maxn];
int idx;

int Find(int x) {
	for (int i = 1; i <= idx; ++i) 
		if (!vi[i] && !(b[i] & 1)) {
			if (!chk[max(b[x], b[i]) - min(b[x], b[i])]) {
				vi[i] = 1;
				if (!lk[i] || Find(lk[i])) {
					lk[i] = x; return 1;
				}
			}
		}
	return 0;
}

int main() {
	gen();
	int n;
	scanf("%d", &n); a[0] = -1;
	for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
	for (int i = 1; i <= n; ++i) {
		if (a[i] - 1 != a[i - 1]) b[++idx] = a[i];
		if (a[i] + 1 != a[i + 1]) b[++idx] = a[i] + 1;
	}
	int ret = 0, cnt = 0;
	for (int i = 1; i <= idx; ++i) if (b[i] & 1) {
		memset(vi, 0, sizeof(vi)); ret += Find(i); ++cnt;
	} 
	return printf("%d\n", ret + ((cnt - ret) / 2 + (idx - cnt - ret) / 2) * 2 + ((cnt - ret) % 2) * 3), 0;
}