#include <map>
#include <set>
#include <ctime>
#include <queue>
#include <stack>
#include <cmath>
#include <vector>
#include <bitset>
#include <cstdio>
#include <cctype>
#include <string>
#include <numeric>
#include <cstring>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std ;
#define int long long
#define rep(i, a, b) for (ll i = (a); i <= (b); ++i)
#define per(i, a, b) for (ll i = (a); i >= (b); --i)
#define loop(it, v) for (auto it = v.begin(); it != v.end(); it++)
#define cont(i, x) for (ll i = head[x]; i; i = edge[i].nex)
#define clr(a) memset(a, 0, sizeof(a))
#define ass(a, cnt) memset(a, cnt, sizeof(a))
#define cop(a, b) memcpy(a, b, sizeof(a))
#define lowbit(x) (x & -x)
#define all(x) x.begin(), x.end()
#define SC(t, x) static_cast <t> (x)
#define ub upper_bound
#define lb lower_bound
#define pqueue priority_queue
#define mp make_pair
#define pb push_back
#define pof pop_front
#define pob pop_back
#define fi first
#define se second
#define y1 y1_
#define Pi acos(-1.0)
#define iv inline void
#define enter putchar('\n')
#define siz(x) ((ll)x.size())
#define file(x) freopen(x".in", "r", stdin),freopen(x".out", "w", stdout)
typedef double db ;
typedef long long ll ;
typedef unsigned long long ull ;
typedef pair <ll, ll> pii ;
typedef vector <ll> vi ;
typedef vector <pii> vii ;
typedef queue <ll> qi ;
typedef queue <pii> qii ;
typedef set <ll> si ;
typedef map <ll, ll> mii ;
typedef map <string, ll> msi ;
const ll maxn = 2e6 + 100 ;
const ll inf = 0x3f3f3f3f ;
const ll iinf = 1 << 30 ;
const ll linf = 2e18 ;
const ll mod = 998244353 ;
const double eps = 1e-7 ;
template <class T = ll> T chmin(T &a, T b) { return a = min(a, b);}
template <class T = ll> T chmax(T &a, T b) { return a = max(a, b);}
template <class T = ll> T read()
{
	T f = 1, a = 0;
	char ch = getchar() ;
	while (!isdigit(ch)) { if (ch == '-') f = -1 ; ch = getchar() ; }
	while (isdigit(ch)) { a =  (a << 3) + (a << 1) + ch - '0' ; ch = getchar() ; }
	return a * f ;
}

ll n, ans;

ll a[maxn], b[maxn], tot;

si s;

vi edge[maxn];

bool is_prime(ll x)
{
	if(x <= 2) return 0;
	rep(i, 2, sqrt(x)) if(x % i == 0) return 0;
	return 1;
}

ll col[maxn];

void paint(ll now, ll x)
{
	if(col[now]) return ;
	col[now] = x;
	for(ll to : edge[now]) paint(to, x ^ 3);
}

ll match[maxn], vis[maxn];

ll dfs(ll now)
{
	for(ll to : edge[now])
	{
		if(vis[to]) continue;
		vis[to] = 1;
		if(!match[to] || dfs(match[to]))
		{
			match[now] = to, match[to] = now;
			return 1;
		}
	}
	return 0;
}

void hungarian()
{
	rep(i, 1, tot)
	{
		if(col[i] == 2) continue;
		rep(j, 1, tot) vis[j] = 0;
		ans += dfs(i);
	}
}

ll odd, even;

signed main()
{
	n = read();
	rep(i, 1, n) a[i] = read();
	a[0] = -114514;
	sort(a + 1, a + n + 1);
	// rep(i, 1, n) printf("%lld%c", a[i], " \n"[i == n]);
	rep(i, 1, n)
	{
		if(a[i - 1] != a[i] - 1) s.insert(a[i]);
		if(a[i + 1] != a[i] + 1) s.insert(a[i] + 1);
	}
	for(ll i : s) b[++ tot] = i;//, printf("%lld ", i);
	// enter;
	rep(i, 1, tot) rep(j, i + 1, tot) if(is_prime(b[j] - b[i])) edge[i].pb(j), edge[j].pb(i);//, printf("%lld -> %lld\n", i, j);
	rep(i, 1, tot) if(!col[i]) paint(i, 1);
	// rep(i, 1, tot) printf("%lld%c", col[i], " \n"[i == tot]);
	hungarian();
	// rep(i, 1, tot) printf("%lld : %lld\n", i, match[i]);
	rep(i, 1, tot)
	{
		if(match[i]) continue;
		if(b[i] & 1) odd ++;
		else even ++;
	}
	ans += odd / 2 * 2, ans += even / 2 * 2;
	if(odd & 1) ans += 3;
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 55680