#if 0
date +%Y.%m.%d

题解先咕着。
#endif
#include <cstdio>
#include <algorithm>
#define debug(...) fprintf(stderr, __VA_ARGS__)

typedef long long ll;

struct {
	inline operator int () { int x; return scanf("%d", &x), x; }
	/* inline operator ll () { ll x; return scanf("%lld", &x), x; } */
	/* template<class T> inline void operator () (T &x) { x = *this; } */
	/* template<class T, class ...A> inline void operator () (T &x, A &...a) */
	/* { x = *this; this -> operator () (a...); } */
} read;

const int maxn = 205;
int a[maxn], ap;
int match[maxn];
bool vis[maxn];
bool nop[10000005];

bool find (int p) {
	for (int i = 1; i <= ap; i ++)
		if (!vis[i] and a[i] & 1 and !nop[std::abs(a[i] - a[p])]) {
			vis[i] = 1;
			if (!match[i] or find(match[i])) {
				match[i] = p;
				return 1;
			}
		}
	return 0;
}

int main () {
	int N = 10000000;
	nop[1] = 1;
	for (int i = 2; i <= N; i ++)
		if (!nop[i]) {
			if (i <= N / i)
				for (int j = i * i; j <= N; j += i)
					nop[j] = 1;
		}

	int n = read;
	for (int i = 1, las = -1; i <= n; i ++) {
		int x = read;
		if (x - 1 == las)
			a[ap] = x;
		else {
			a[++ ap] = x - 1;
			a[++ ap] = x;
		}
		las = x;
	}

	int tot = 0;
	for (int i = 1; i <= ap; i ++)
		if (!(a[i] & 1)) {
			std::fill(vis, vis + ap + 1, 0);
			tot += find(i);
		}

	int A = -tot, B = -tot;
	for (int i = 1; i <= ap; i ++)
		a[i] & 1 ? ++ A : ++ B;

	printf("%d\n", ap - tot + (A & 1));
}
