#include<iostream>
using namespace std;
int checkn(int k, int n)
{
int i=0;
while(k>0)
{
i++;
k=k/10;
}
if (i==n) return 1;
return 0;
}
int nguyento(int k)
{
for(int i=2;i*i<=k;i++)
{
if(k%i==0) return 0;
}
return 1;
}
int tong(int k)
{
int tong;
while(k>0)
{
tong=tong+k%10;
k=k/10;
}
if(nguyento(tong)) return 1;
return 0;
}
int chuso(int k)
{
while(k>0)
{
if(nguyento(k%10)==0) return 0;
k=k/10;
}
return 1;
}
int main()
{
int k, n; cin>>k>>n;
if(checkn(k,n)&&nguyento(k)&&tong(k)&&chuso(k))
cout<<"YES\n";
else cout<<"NO\n";
return 0;
}
I2luY2x1ZGU8aW9zdHJlYW0+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IGNoZWNrbihpbnQgaywgaW50IG4pCnsKCWludCBpPTA7Cgl3aGlsZShrPjApCgl7CgkJaSsrOwoJCWs9ay8xMDsKCX0KCWlmIChpPT1uKSByZXR1cm4gMTsKCXJldHVybiAwOwp9CgppbnQgbmd1eWVudG8oaW50IGspCnsKCWZvcihpbnQgaT0yO2kqaTw9aztpKyspCgl7CgkJaWYoayVpPT0wKSByZXR1cm4gMDsKCX0KCXJldHVybiAxOwp9CgppbnQgdG9uZyhpbnQgaykKewoJaW50IHRvbmc7Cgl3aGlsZShrPjApCgl7CgkJdG9uZz10b25nK2slMTA7CgkJaz1rLzEwOwoJfQoJaWYobmd1eWVudG8odG9uZykpIHJldHVybiAxOwoJcmV0dXJuIDA7Cn0KCmludCBjaHVzbyhpbnQgaykKewoJd2hpbGUoaz4wKQoJewoJCWlmKG5ndXllbnRvKGslMTApPT0wKSByZXR1cm4gMDsKCQlrPWsvMTA7Cgl9CglyZXR1cm4gMTsKfQoKaW50IG1haW4oKQp7CglpbnQgaywgbjsgY2luPj5rPj5uOwoJaWYoY2hlY2tuKGssbikmJm5ndXllbnRvKGspJiZ0b25nKGspJiZjaHVzbyhrKSkKCWNvdXQ8PCJZRVNcbiI7CgllbHNlIGNvdXQ8PCJOT1xuIjsKCXJldHVybiAwOwp9Cgo=