#include <iostream>
#include <math.h>
using namespace std;
#define MAX 100
void NhapmangSNT(int a[], int &n);
int SoPhanTuChuaY(int a[], int n, int y);
void NhapmangSNT(int a[], int &n)
{
return;
}
bool checknum(int n, int k)
{
while(n > 0)
{
if(k == int(n % 10))
return true;
n /= 10;
}
return false;
}
bool checkprime(int n)
{
if(n < 2)
return false;
for(int i = 2; i <= int(sqrt(n)); i++)
if(n % i == 0)
return false;
return true;
}
int SoPhanTuChuaY(int a[], int n, int y)
{
cin >> n;
int arr[10001], dem = 1, ans = 0;
for(int i = 2; i <= 10001; i++)
if(dem <= n)
if(checkprime(i))
{
if(checknum(i, y))
ans++;
dem++;
}
return ans;
}
int main()
{
int a[MAX], n, y;
cin >> y;
NhapmangSNT(a, n);
cout << SoPhanTuChuaY(a, n, y) << endl;;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8bWF0aC5oPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwojZGVmaW5lIE1BWCAxMDAKCnZvaWQgTmhhcG1hbmdTTlQoaW50IGFbXSwgaW50ICZuKTsKaW50IFNvUGhhblR1Q2h1YVkoaW50IGFbXSwgaW50IG4sIGludCB5KTsKCnZvaWQgTmhhcG1hbmdTTlQoaW50IGFbXSwgaW50ICZuKQp7CiAgICByZXR1cm47Cn0KCmJvb2wgY2hlY2tudW0oaW50IG4sIGludCBrKQp7CiAgICB3aGlsZShuID4gMCkKICAgIHsKICAgICAgICBpZihrID09IGludChuICUgMTApKQogICAgICAgICAgICByZXR1cm4gdHJ1ZTsKICAgICAgICBuIC89IDEwOwogICAgfQogICAgcmV0dXJuIGZhbHNlOwp9Cgpib29sIGNoZWNrcHJpbWUoaW50IG4pCnsKICAgIGlmKG4gPCAyKQogICAgICAgIHJldHVybiBmYWxzZTsKICAgIGZvcihpbnQgaSA9IDI7IGkgPD0gaW50KHNxcnQobikpOyBpKyspCiAgICAgICAgaWYobiAlIGkgPT0gMCkKICAgICAgICAgICAgcmV0dXJuIGZhbHNlOwogICAgcmV0dXJuIHRydWU7Cn0KCmludCBTb1BoYW5UdUNodWFZKGludCBhW10sIGludCBuLCBpbnQgeSkKewogICAgY2luID4+IG47CiAgICBpbnQgYXJyWzEwMDAxXSwgZGVtID0gMSwgYW5zID0gMDsKICAgIGZvcihpbnQgaSA9IDI7IGkgPD0gMTAwMDE7IGkrKykKICAgICAgICBpZihkZW0gPD0gbikKICAgICAgICAgICAgaWYoY2hlY2twcmltZShpKSkKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgaWYoY2hlY2tudW0oaSwgeSkpCiAgICAgICAgICAgICAgICAgICAgYW5zKys7CiAgICAgICAgICAgICAgICBkZW0rKzsKICAgICAgICAgICAgfQogICAgcmV0dXJuIGFuczsKfQoKaW50IG1haW4oKQp7CiAgICBpbnQgYVtNQVhdLCBuLCB5OwogICAgY2luID4+IHk7CiAgICBOaGFwbWFuZ1NOVChhLCBuKTsKICAgIGNvdXQgPDwgU29QaGFuVHVDaHVhWShhLCBuLCB5KSA8PCBlbmRsOzsKICAgIHJldHVybiAwOwp9Cgo=