// Copyright (C) 2017 __debug.

// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; version 3

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program; If not, see <http://www.gnu.org/licenses/>.


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/priority_queue.hpp>

#define x first
#define y second
#define MP std::make_pair
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
#ifdef __linux__
#define getchar getchar_unlocked
#define putchar putchar_unlocked
#endif

using std::pair;
using std::vector;
using std::string;

typedef long long LL;
typedef pair<int, int> Pii;

const int oo = 0x3f3f3f3f;

template<typename T> inline bool chkmax(T &a, T b) { return a < b ? a = b, true : false; }
template<typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, true : false; }
string procStatus()
{
    std::ifstream t("/proc/self/status");
    return string(std::istreambuf_iterator<char>(t), std::istreambuf_iterator<char>());
}
template<typename T> T read(T &x)
{
    int f = 1;
    char ch = getchar();
    for (; !isdigit(ch); ch = getchar())
        f = (ch == '-' ? -1 : 1);
    for (x = 0; isdigit(ch); ch = getchar())
        x = 10 * x + ch - '0';
    return x *= f;
}
template<typename T> void write(T x)
{
    if (x == 0) {
        putchar('0');
        return;
    }
    if (x < 0) {
        putchar('-');
        x = -x;
    }
    static char s[20];
    int top = 0;
    for (; x; x /= 10)
        s[++top] = x % 10 + '0';
    while (top)
        putchar(s[top--]);
}
// EOT

const int MAXN = 105, RNG = 1e7 + 5;

int N;
int X[MAXN];

void input()
{
    read(N);
    for (int i = 1; i <= N; ++i) {
        read(X[i]);
    }
}

int primes[RNG], totprimes;
bool composite[RNG];

void sieve(int n)
{
    composite[1] = true;
    for (int i = 2; i <= n; ++i) {
        if (!composite[i])
            primes[totprimes++] = i;
        for (int j = 0, x; (x = primes[j] * i) <= n; ++j) {
            composite[x] = true;
            if (i % primes[j] == 0)
                break;
        }
    }
}

vector<int> odd, even;
bool G[MAXN][MAXN];
int match[MAXN];
bool vis[MAXN];

bool augment(int u)
{
    for (int v = 0; v < SZ(even); ++v) {
        if (G[u][v] && !vis[v]) {
            vis[v] = true;
            if (!~match[v] || augment(match[v])) {
                match[v] = u;
                return true;
            }
        }
    }
    return false;
}

void solve()
{
    sieve(X[N]);

    X[0] = -1;
    X[N + 1] = RNG;
    for (int i = 1; i <= N; ++i) {
        if (X[i - 1] + 1 < X[i])
            (X[i] & 1 ? odd : even).push_back(X[i]);
        if (X[i] + 1 < X[i + 1])
            ((X[i] + 1) & 1 ? odd : even).push_back(X[i] + 1);
    }

    for (int i = 0; i < SZ(odd); ++i) {
        for (int j = 0; j < SZ(even); ++j) {
            if (!composite[std::abs(odd[i] - even[j])])
                G[i][j] = true;
        }
    }

    int t = 0;
    memset(match, -1, sizeof(match));
    for (int i = 0; i < SZ(odd); ++i) {
        memset(vis, 0, sizeof(vis));
        t += augment(i);
    }
    int ans = t + ((SZ(odd) - t) / 2 + (SZ(even) - t) / 2) * 2 + (SZ(odd) - t) % 2 * 3;

    printf("%d\n", ans);
}

int main()
{
#ifdef __DEBUG
    freopen("F.in", "r", stdin);
    freopen("F.out", "w", stdout);
#endif

    input();
    solve();

    return 0;
}

//              滥竽充数
//            [先秦] 韩非
//
// 齐宣王使人吹竽，必三百人。
// 南郭处士请为王吹竽，宣王说之，廪食以数百人。
// 宣王死，湣王立，好一一听之，处士逃。


Measured memory_bytes: 14720