#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
int sum_digits(int number) {
int ret = 0;
do {
ret += number % 10;
number /= 10;
} while (number > 0);
return ret;
}
const bool debug = true;
int main() {
int sum, digit;
std::cin >> sum >> digit;
const int NMAX = (int)1e5;
std::vector<bool> is_prime(1+NMAX,1);
is_prime[0] = is_prime[1] = false;
for (int i = 2; i * i <= NMAX; ++i) {
if (!is_prime[i]) continue;
for (int j = i * i; j <= NMAX; j += i) {
is_prime[j] = false;
}
}
if (debug) {
std::vector<std::vector<int>> cnt(50,std::vector<int>(10,0));
for (int i = 10000; i <= NMAX; ++i) {
if (is_prime[i]) cnt[sum_digits(i)][i / 10000]++;
}
for (int i = 0; i < 50; ++i) {
int s = std::accumulate(cnt[i].begin(), cnt[i].end(), 0);
if (s == 0) continue;
printf("cnt[%02d]=%3d:", i, s);
for (int d = 0; d < 10; ++d) {
printf(" [%d]=%3d", d, cnt[i][d]);
}
printf("\n");
}
}
std::vector<int> primes;
for (int i = 10000; i <= NMAX; ++i) {
if (is_prime[i] && sum_digits(i) == sum) {
primes.push_back(i);
}
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8YWxnb3JpdGhtPgojaW5jbHVkZSA8bnVtZXJpYz4KCmludCBzdW1fZGlnaXRzKGludCBudW1iZXIpIHsKICAgIGludCByZXQgPSAwOwogICAgZG8gewogICAgICAgIHJldCArPSBudW1iZXIgJSAxMDsKICAgICAgICBudW1iZXIgLz0gMTA7CiAgICB9IHdoaWxlIChudW1iZXIgPiAwKTsKICAgIHJldHVybiByZXQ7Cn0KCmNvbnN0IGJvb2wgZGVidWcgPSB0cnVlOwoKaW50IG1haW4oKSB7CiAgICAKICAgIGludCBzdW0sIGRpZ2l0OwogICAgc3RkOjpjaW4gPj4gc3VtID4+IGRpZ2l0OwogICAgCiAgICBjb25zdCBpbnQgTk1BWCA9IChpbnQpMWU1OwogICAgc3RkOjp2ZWN0b3I8Ym9vbD4gaXNfcHJpbWUoMStOTUFYLDEpOwogICAgaXNfcHJpbWVbMF0gPSBpc19wcmltZVsxXSA9IGZhbHNlOwogICAgZm9yIChpbnQgaSA9IDI7IGkgKiBpIDw9IE5NQVg7ICsraSkgewogICAgICAgIGlmICghaXNfcHJpbWVbaV0pIGNvbnRpbnVlOwogICAgICAgIGZvciAoaW50IGogPSBpICogaTsgaiA8PSBOTUFYOyBqICs9IGkpIHsKICAgICAgICAgICAgaXNfcHJpbWVbal0gPSBmYWxzZTsKICAgICAgICB9CiAgICB9CiAgICAKICAgIGlmIChkZWJ1ZykgewogICAgICAgIHN0ZDo6dmVjdG9yPHN0ZDo6dmVjdG9yPGludD4+IGNudCg1MCxzdGQ6OnZlY3RvcjxpbnQ+KDEwLDApKTsKICAgICAgICBmb3IgKGludCBpID0gMTAwMDA7IGkgPD0gTk1BWDsgKytpKSB7CiAgICAgICAgICAgIGlmIChpc19wcmltZVtpXSkgY250W3N1bV9kaWdpdHMoaSldW2kgLyAxMDAwMF0rKzsKICAgICAgICB9CiAgICAgICAgZm9yIChpbnQgaSA9IDA7IGkgPCA1MDsgKytpKSB7CiAgICAgICAgICAgIGludCBzID0gc3RkOjphY2N1bXVsYXRlKGNudFtpXS5iZWdpbigpLCBjbnRbaV0uZW5kKCksIDApOwogICAgICAgICAgICBpZiAocyA9PSAwKSBjb250aW51ZTsKICAgICAgICAgICAgcHJpbnRmKCJjbnRbJTAyZF09JTNkOiIsIGksIHMpOwogICAgICAgICAgICBmb3IgKGludCBkID0gMDsgZCA8IDEwOyArK2QpIHsKICAgICAgICAgICAgICAgIHByaW50ZigiIFslZF09JTNkIiwgZCwgY250W2ldW2RdKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBwcmludGYoIlxuIik7CiAgICAgICAgfQogICAgfQogICAgCiAgICBzdGQ6OnZlY3RvcjxpbnQ+IHByaW1lczsKICAgIGZvciAoaW50IGkgPSAxMDAwMDsgaSA8PSBOTUFYOyArK2kpIHsKICAgICAgICBpZiAoaXNfcHJpbWVbaV0gJiYgc3VtX2RpZ2l0cyhpKSA9PSBzdW0pIHsKICAgICAgICAgICAgcHJpbWVzLnB1c2hfYmFjayhpKTsKICAgICAgICB9CiAgICB9CiAgICAKICAgIAogICAgcmV0dXJuIDA7Cn0=