#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
// const int dy[] = {1, 1, 0, -1, -1, -1, 0, 1},
//           dx[] = {0, -1, -1, -1, 0, 1, 1, 1};

struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    cerr << fixed << setprecision(10);
  }
} iosetup;
/*-------------------------------------------------*/
vector<bool> sieve_of_eratosthenes(int num) {
  vector<bool> res(num + 1, true);
  if (num >= 0) {
    res[0] = false;
    if (num >= 1) res[1] = false;
  }
  for (int i = 2; i * i <= num; ++i) if (res[i]) {
    for (int j = i * i; j <= num; j += i) res[j] = false;
  }
  return res;
}

struct HopcroftKarp {
  vector<int> match;

  HopcroftKarp(int left, int right) : left(left), graph(left), match(left + right, -1), level(left), used(left, -1) {}

  void add_edge(int u, int v) { graph[u].emplace_back(left + v); }

  int solve() {
    int res = 0;
    while (true) {
      bfs();
      int tmp = 0;
      REP(i, left) if (match[i] == -1) {
        if (dfs(i)) ++tmp;
        ++timestamp;
      }
      if (tmp == 0) return res;
      res += tmp;
    }
  }

private:
  int left, timestamp = 0;
  vector<vector<int> > graph;
  vector<int> level, used;

  void bfs() {
    fill(ALL(level), -1);
    queue<int> que;
    REP(i, left) {
      if (match[i] == -1) {
        que.emplace(i);
        level[i] = 0;
      }
    }
    while (!que.empty()) {
      int ver = que.front(); que.pop();
      for (int e : graph[ver]) if (match[e] != -1 && level[match[e]] == -1) {
        level[match[e]] = level[ver] + 1;
        que.emplace(match[e]);
      }
    }
  }

  bool dfs(int ver) {
    used[ver] = timestamp;
    for (int e : graph[ver]) {
      int tmp = match[e];
      if (tmp == -1 || (used[tmp] < timestamp && level[tmp] == level[ver] + 1 && dfs(tmp))) {
        used[ver] = timestamp;
        match[e] = ver;
        match[ver] = e;
        return true;
      }
    }
    return false;
  }
};

int main() {
  const int X = 10000000;
  vector<bool> primes = sieve_of_eratosthenes(X);
  int n; cin >> n;
  vector<int> a(X + 2, 0);
  while (n--) {
    int x; cin >> x;
    a[x] = 1;
  }
  vector<int> b_odd, b_even;
  FOR(i, 1, X + 2) {
    if (a[i - 1] ^ a[i]) (i & 1 ? b_odd : b_even).emplace_back(i);
  }
  int l = b_odd.size(), r = b_even.size();
  HopcroftKarp hk(l, r);
  REP(i, l) REP(j, r) {
    if (primes[abs(b_odd[i] - b_even[j])]) hk.add_edge(i, j);
  }
  int k = hk.solve();
  cout << k + ((l - k) / 2 + (r - k) / 2) * 2 + ((l - k) & 1) * 3 << '\n';
  return 0;
}


Measured memory_bytes: 41084