#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 4000001;
const long double eps = 1E-14;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a % b);
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime MOD
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

mint pw(mint a, ll b) {
	if (b == 0) { return 1; }
	mint ret = pw(a, b >> 1);
	ret *= ret;
	if (b & 1) { ret *= a; }
	return ret;
}

typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;

typedef vector<mint> vmint;
typedef vector<vector<mint>> vvmint;
typedef vector<vector<vector<mint>>> vvvmint;

//////////////////////////////////////

struct Ford_Fulkerson {

	struct f_edge {
		ll to;
		ll cap;
		ll fl;
		ll rev;//反対方向の辺の添え字
	};


	ll N;
	ll s, t;
	vector<vector<edge>> g;//グラフ片方向にのみ張る、flowで双方向に構築
	vector<vector<f_edge>> flow;
	ll maxflow;

	vector<bool> see;
	ll dfs(ll v, ll x) {
		see[v] = 1;

		if (v == t) { return x; }

		rep(i, flow[v].size()) {
			const auto e = flow[v][i];

			if (see[e.to] == 1) { continue; }
			if (e.cap == e.fl) { continue; }

			ll y = min(x, e.cap - e.fl);

			y = dfs(e.to, y);
			if (y == 0) { continue; }

			flow[v][i].fl += y;
			flow[e.to][e.rev].fl -= y;
			return y;
		}

		return 0;
	}

	Ford_Fulkerson(ll N0, vector<vector<edge>> g0, ll s0, ll t0) {
		N = N0;
		g = g0;
		s = s0;
		t = t0;

		flow.resize(N + 1);
		repn(v, N) {
			for (edge e : g[v]) {
				ll w = e.to;
				flow[v].push_back({ w,e.d,0,flow[w].size() });
				flow[w].push_back({ v,0,0,flow[v].size() - 1 });
			}
		}

		maxflow = 0;

		if (s == t) { maxflow = INF; return; }

		while (1) {
			see.assign(N + 1, 0);
			ll f = dfs(s, INF);
			if (f == 0) { break; }
			maxflow += f;
		}

		maxflow = min(INF, maxflow);

		return;

	}
};

bool odprime(ll x) {
	if (x <= 2) { return 0; }
	for (ll i = 2; i * i <= x; i++) {
		if (x % i == 0) { return 0; }
	}

	return 1;
}

int main() {

	ll N;
	cin >> N;
	vll x(N + 1);
	repn(i, N) cin >> x[i];

	ll M = 20000000;
	vector<bool> omote(M + 1, 1);
	repn(i, N) { omote[x[i]] = 0; }

	vector<ll> a(1, 0);
	rep(i, M) { if (omote[i] != omote[i + 1]) { a.push_back(i); } }
	ll K = a.size() - 1;

	vector<vector<edge>> g(K + 3);
	ll ev = 0;
	ll od = 0;

	repn(i, K) {
		if (a[i] % 2 == 1) { g[K + 1].push_back({ 0,K + 1,i,1 }); od++; }
		else { g[i].push_back({ 0,i,K + 2,1 }); ev++; }
	}

	repn(i, K)repn(j, K) {
		if (a[i] % 2 == 1 && a[j] % 2 == 0 && odprime(abs(a[i] - a[j]))) {
			g[i].push_back({0,i,j,1});
		}
	}

	Ford_Fulkerson fd(K+2, g, K + 1, K + 2);

	ll ans = fd.maxflow;
	od -= ans;
	ev -= ans;
	ans += od / 2 * 2;
	ans += ev / 2 * 2;
	if (od % 2 == 1) { ans += 3; }

	cout << ans << endl;

	


}

Measured memory_bytes: 3712