#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcount
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define df(x) int x = in()
#define dame { puts("-1"); return 0;}
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,vector<T>,greater<T> >
#define bn(x) ((1<<x)-1)
#define newline puts("")
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
inline void priv(vi a) { rep(i,sz(a)) printf("%d%c",a[i],i==sz(a)-1?'\n':' ');}
template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const vector<T>&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,const vector<T>&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;

// linear sieve
vi ps, pf;
void sieve(int mx) {
  pf = vi(mx);
  rep(i,mx) pf[i] = i;
  for (int i = 2; i < mx; ++i) {
    if (pf[i] == i) ps.pb(i);
    for (int j = 0; j < sz(ps) && ps[j] <= pf[i]; ++j) {
      int x = ps[j]*i;
      if (x >= mx) break;
      pf[x] = ps[j];
    }
  }
}
inline bool isp(int x) { return pf[x] == x && x >= 2;}
//

// binary matching
struct match {
  vi used;
  vvi to;
  vi p;
  int n, m;
  match(int n, int m):used(n),to(n),p(m,-1),n(n),m(m){}
  void add(int a, int b) { to[a].pb(b);}
  bool dfs(int v){
    if(used[v]) return false;
    used[v] = 1;
    rep(i,sz(to[v])) {
      int u = to[v][i];
      if (p[u] == -1 || dfs(p[u])){
        p[u] = v;
        return true;
      }
    }
    return false;
  }
  int solve(){
    int res = 0;
    rep(i,n) {
      rep(j,n) used[j] = 0;
      if(dfs(i)) ++res;
    }
    return res;
  }
};
//



int main() {
  sieve(10000005);
  int n;
  scanf("%d",&n);
  vi x(n);
  cin>>x;
  vi a;
  int pre = -INF;
  for (int s : x) {
    if (pre == s-1) {
      a.pop_back();
    } else {
      a.pb(s);
    }
    a.pb(s+1);
    pre = s;
  }
  vvi d(2);
  for (int s : a) {
    d[s&1].pb(s);
  }
  n = sz(d[0]);
  int m = sz(d[1]);
  match g(n,m);
  rep(i,n)rep(j,m) {
    if (isp(abs(d[0][i]-d[1][j]))) g.add(i,j);
  }
  int c = g.solve();
  n -= c; m -= c;
  int ans = (n/2+m/2)*2+c;
  n %= 2; m %= 2;
  if (n) ans += 3;
  cout<<ans<<endl;
  return 0;
}






















Measured memory_bytes: 45552