#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
bool check_length (int K, int N) {
int length = 0;
while (K) {
K /= 10;
length++;
}
return length==N;
}
bool isPrime (int K) {
if (K==2 || K==3) return true;
if (K<2 || K%2==0) return false;
for (int i=2; i<=sqrt(K); i++) {
if (K%i==0) return false;
}
return true;
}
bool check_sum (int K) {
int sum = 0;
while (K>0) {
sum += K%10;
K /= 10;
}
return isPrime(sum);
}
bool check_digit (int K) {
while (K>0) {
if (!isPrime(K%10)) return false;
K /= 10;
}
return true;
}
int main () {
cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
int K, N;
cin >> K >> N;
if (check_length(K, N) && isPrime(K) && check_sum(K) && check_digit(K)) {
cout << "YES";
}
else {
cout << "NO";
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgp0eXBlZGVmIGxvbmcgbG9uZyBsbDsKCmJvb2wgY2hlY2tfbGVuZ3RoIChpbnQgSywgaW50IE4pIHsKICAgIGludCBsZW5ndGggPSAwOwogICAgd2hpbGUgKEspIHsKICAgICAgICBLIC89IDEwOwogICAgICAgIGxlbmd0aCsrOwogICAgfQogICAgcmV0dXJuIGxlbmd0aD09TjsKfQoKYm9vbCBpc1ByaW1lIChpbnQgSykgewogICAgaWYgKEs9PTIgfHwgSz09MykgcmV0dXJuIHRydWU7CiAgICBpZiAoSzwyIHx8IEslMj09MCkgcmV0dXJuIGZhbHNlOwogICAgZm9yIChpbnQgaT0yOyBpPD1zcXJ0KEspOyBpKyspIHsKICAgICAgICBpZiAoSyVpPT0wKSByZXR1cm4gZmFsc2U7CiAgICB9CiAgICByZXR1cm4gdHJ1ZTsKfQoKYm9vbCBjaGVja19zdW0gKGludCBLKSB7CiAgICBpbnQgc3VtID0gMDsKICAgIHdoaWxlIChLPjApIHsKICAgICAgICBzdW0gKz0gSyUxMDsKICAgICAgICBLIC89IDEwOwogICAgfQogICAgcmV0dXJuIGlzUHJpbWUoc3VtKTsKfQoKYm9vbCBjaGVja19kaWdpdCAoaW50IEspIHsKICAgIHdoaWxlIChLPjApIHsKICAgICAgICBpZiAoIWlzUHJpbWUoSyUxMCkpIHJldHVybiBmYWxzZTsKICAgICAgICBLIC89IDEwOwogICAgfQogICAgcmV0dXJuIHRydWU7Cn0KCmludCBtYWluICgpIHsKICAgIGNpbi50aWUoMCk7IGNvdXQudGllKDApOyBpb3NfYmFzZTo6c3luY193aXRoX3N0ZGlvKDApOwogICAgCiAgICBpbnQgSywgTjsKICAgIGNpbiA+PiBLID4+IE47CgogICAgaWYgKGNoZWNrX2xlbmd0aChLLCBOKSAmJiBpc1ByaW1lKEspICYmIGNoZWNrX3N1bShLKSAmJiBjaGVja19kaWdpdChLKSkgewogICAgICAgIGNvdXQgPDwgIllFUyI7CiAgICB9CiAgICBlbHNlIHsKICAgICAgICBjb3V0IDw8ICJOTyI7CiAgICB9CiAgICByZXR1cm4gMDsKfQ==