#include <bits/stdc++.h>
using namespace std;

vector<int> odd, even;
vector<int> prime_Lst;

template<typename T>
class Maxflow
{
    struct edge { int to; T cap; int rev; };
    std::vector<std::vector<edge> > edges;
    std::vector<int> level;
    std::vector<int> iter;
    std::vector<int> used;

    void bfs(int s)
    {
        level = std::vector<int>(edges.size(), -1);
        std::queue<int> q;
        level[s] = 0;
        q.push(s);
        while (!q.empty())
        {
            int v = q.front();
            q.pop();
            for (edge &e : edges[v])
            {
                if (e.cap > 0 && level[e.to] < 0)
                {
                    level[e.to] = level[v] + 1;
                    q.push(e.to);
                }
            }
        }
    }

    T dfs_d(int v, int goal, T f)
    {
        if (v == goal) return f;
        for (int &i = iter[v]; i < (int)edges[v].size(); i++)
        {
            edge &e = edges[v][i];
            if (e.cap > 0 && level[v] < level[e.to])
            {
                T d = dfs_d(e.to, goal, std::min(f, e.cap));
                if (d > 0)
                {
                    e.cap -= d;
                    edges[e.to][e.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;
    }

    T dfs_ff(int v, int goal, T f)
    {
        if (v == goal) return f;
        used[v] = true;
        for (int i = 0; i < (int)edges[v].size(); i++)
        {
            edge &e = edges[v][i];
            if (e.cap > 0 && !used[e.to])
            {
                T d = dfs_ff(e.to, goal, std::min(f, e.cap));
                if (d > 0)
                {
                    e.cap -= d;
                    edges[e.to][e.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;
    }

public:
    Maxflow(int N) { edges.resize(N); }
    void add_edge(int from, int to, T capacity)
    {
        edges[from].push_back(edge{to, capacity, (int)edges[to].size()});
        edges[to].push_back(edge{from, (T)0, (int)edges[from].size() - 1});
    }

    T Dinic(int s, int t)
    {
        constexpr T INF = std::numeric_limits<T>::max();
        T flow = 0;
        while (true)
        {
            bfs(s);
            if (level[t] < 0) return flow;
            iter = std::vector<int>(edges.size(), 0);
            T f;
            while ((f = dfs_d(s, t, INF)) > 0) flow += f;
        }
    }

    T FF(int s, int t)
    {
        constexpr T INF = std::numeric_limits<T>::max();
        T flow = 0;
        while (true)
        {
            used = std::vector<int>(edges.size(), 0);
            T f = dfs_ff(s, t, INF);
            if (f == 0) return flow;
            flow += f;
        }
    }
};

void find_prime(int t)
{
    vector<bool> ok(t+1, true);
    ok[0] = ok[1] = false;
    for (long long i=2; i<=t; i++)
    {
        if (ok[i] && i>2) prime_Lst.push_back(i);
        for (long long j=i; j<=t; j += i) ok[j] = false;
    }
}

signed main()
{
    int len;
    cin >> len;
    int tmp = -1;
    for (int i=0; i<len; i++)
    {
        cin >> tmp;
        if (tmp&1)
        {
            if (odd.size() == 0 || odd.back() != tmp)
            {
                odd.push_back(tmp);
            }
            else
            {
                odd.pop_back();
            }
            even.push_back(tmp+1);
        }
        else
        {
            if (even.size() == 0 || even.back() != tmp)
            {
                even.push_back(tmp);
            }
            else
            {
                even.pop_back();
            }
            odd.push_back(tmp+1);
        }
    }

    find_prime(tmp);

    int N = odd.size(), M = even.size();
    Maxflow<int> flow(1+N+M+1);
    for (int i=1; i<=N; i++) flow.add_edge(0, i, 1);
    for (int i=1; i<=M; i++) flow.add_edge(N+i, 1+N+M, 1);
    for (int i=1; i<=N; i++)
    {
        for (int j=1; j<=M; j++)
        {
            if (binary_search(prime_Lst.begin(), prime_Lst.end(), abs(odd[i-1] - even[j-1])))
            {
                flow.add_edge(i, N+j, 1);
                // cout << odd[i-1] << " " << even[j-1] << endl;
            }
        }
    }
    // for (auto p : prime_Lst) cout << p << " ";

    int res = flow.FF(0, 1+N+M);
    // cout << res << endl;
    N -= res; M -= res;
    
    res += N+M;
    if (N&1) res++;
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 7668