#include<bits/stdc++.h>
using namespace std;
bool susu(int h)//判断素数
{
for(int i=1;i<=sqrt(h)/*从1——n判断*/;i++)
{
if(h<2)
{
return false;
}
if(h%i==0)
{
return false;
}
}
return true;
}
bool hehe(int h)//判断回文数
{
int t=h,n=0;
while(t)
{
n=n*10+t%10;
t/=10;
}
if(n==h)
{
return true;
}
}
int main()
{
int h,m=0;
cin>>h;
for(int i=11;i<=h;i++)
{
if(susu(i)&&hehe(i))
{
m++;
}
}
cout<<m<<'\n';
return 0;
}