#include <bits/stdc++.h>
#define ll long long
#define REP(i, n) for (ll i = 0, max_i = (n); i < max_i; i++)
#define REPI(i, a, b) for (ll i = (a), max_i = (b); i < max_i; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define fi first
#define se second
#define pb push_back
#define debug(x) cerr << #x << ": " << (x) << endl
#define debug2(x, y) cerr << #x << ": " << (x) << " " << #y << ": " << y << endl;
#define int long long
using namespace std;
using II = pair<int, int>;
using VII = vector<II>;
using VI = vector<int>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
template <class T = int> inline T in() { T x; cin >> x; return x; }
template <class T = int> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template <class T = int> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template <class T> ostream& operator<<(ostream &s, const vector<T>& d) { int n = d.size(); REP (i, n) s << d[i] << " "; return s; }
template <class T> ostream& operator<<(ostream &s, const vector<vector<T>>& dd) { for (vector<T> d: dd) s << d << endl; return s; }
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); } } fast;
const int MOD = 1e9 + 7;
struct Eratosthenes {
  vector<bool> is_prime;
  VI primes;
  Eratosthenes(int n) {
    is_prime = vector<bool>(n, true); is_prime[1] = false;
    REPI (i, 2, n) {
      if (!is_prime[i]) { continue; }
      for (int j = i * 2; j < n; j += i) {
        is_prime[j] = false;
      }
    }
    REPI (i, 2, n) {
      if (is_prime[i]) {
        primes.push_back(i);
      }
    }
  }
};
// Dinic法 O(E * V^2)
class Graph {
  int t; // ゴール
  VI level, iter;
  void bfs(int s) {
    for (int i = 0; i < level.size(); i++) level[i] = -1;
    queue<int> que;
    level[s] = 0;
    que.push(s);
    while (!que.empty()) {
      int v = que.front(); que.pop();
      for (int i = 0; i < G[v].size(); i++) {
        edge &e = G[v][i];
        if (e.cap > 0 && level[e.to] < 0) {
          level[e.to] = level[v] + 1;
          que.push(e.to);
        }
      }
    }
  }
  int dfs(int v, int f) {
    if (v == t) return f;
    for (int &i = iter[v]; i < G[v].size(); i++) {
      edge &e = G[v][i];
      if (e.cap > 0 && level[v] < level[e.to]) {
        int d = dfs(e.to, min(f, e.cap));
        if (d > 0) {
          e.cap -= d;
          G[e.to][e.rev].cap += d;
          return d;
        }
      }
    }
    return 0;
  }
public:
  int V;
  struct edge {int to, cap, rev; };
  vector<vector<edge>> G;
  Graph(int V) : V(V), G(V), level(V), iter(V) {}

  void add_edge(int from, int to, int cap) {
    G[from].push_back(edge{ to, cap, (int)G[to].size() });
    G[to].push_back(edge{ from, 0, (int)G[from].size() - 1 });
  }

  int max_flow(int s, int t) {
    int flow = 0;
    this->t = t;
    while (1) {
      bfs(s);
      if (level[t] < 0) return flow;
      for (int i = 0; i < iter.size(); i++) iter[i] = 0;
      int f;
      while ((f = dfs(s, (1LL << 60))) > 0) {
        flow += f;
      }
    }
  }
};

signed main() {
  int N = in();
  VI xs(N + 2); xs[0] = -1; xs[N + 1] = 1e8;
  REP (i, N) cin >> xs[i + 1];
  VI odds, evens;
  REPI (i, 1, N + 1) {
    if (xs[i - 1] + 1 != xs[i]) {
      (xs[i] % 2 ? odds : evens).push_back(xs[i]);
    }
    if (xs[i + 1] != xs[i] + 1) {
      ((xs[i] + 1) % 2 ? odds : evens).push_back(xs[i] + 1);
    }
  }
  int n = odds.size();
  int m = evens.size();

  Eratosthenes er(1e7 + 10);
  Graph g(n + m + 2);
  int s = n + m, t = n + m + 1;
  REP (i, n) {
    REP (j, m) {
      if (er.is_prime[abs(odds[i] - evens[j])]) {
        g.add_edge(i, n + j, 1);
      }
    }
  }
  REP (i, n) {
    g.add_edge(s, i, 1);
  }
  REP (j, m) {
    g.add_edge(n + j, t, 1);
  }

  int k = g.max_flow(s, t);
  cout << k + 2 * ((n - k) / 2 + (m - k) / 2) + 3 * ((n - k) % 2) << endl;
}


Measured memory_bytes: 11884