#include <bits/stdc++.h>
using namespace std;
int n,a[1005];
inline int Prime(int x)
{
int i;
if(x<=1)return 0;
if(x==2)return 1;
if(x%2==0)return 0;
for(i=3;i*i<=x;i++)
if(x%i==0)return 0;
return 1;
}
inline int Invers(int x)
{
int numar=0;
while(x!=0)
{
numar=numar*10+x%10;
x/=10;
}
return numar;
}
int main()
{
int i,s,maxim;
cin>>n;
for(i=1;i<=n;i++)
cin>>a[i];
s=1;
maxim=0;
for(i=2;i<=n;i++)
{
if(Prime(a[i])==1 and Prime(Invers(a[i]))==1 and Prime(a[i-1])==1 and Prime(Invers(a[i-1]))==1)
s++;
else s=1;
maxim=max(maxim,s);
}
cout<<maxim<<"\n";
return 0;
}