d043ce6cc397f941223289f4cbe74ad5f1a007bd88d889a31d2eb645430fcf07
// https://szkopul.edu.pl/problemset/problem/zuhxhEWkqUBA_QpwCLsYqn68/site/?key=statement
#include <algorithm>
#include <cstdint>
#include <iostream>
#include <queue>
#include <vector>
bool isPrime(long long a) {
if (a == 1) {
return false;
}
int licznik = 0;
for (int i = 1; (long long)i * i <= a; i++) {
if (a % i == 0) {
licznik++;
if (a / i != i) {
licznik++;
}
}
}
return licznik <= 2;
}
int main() {
std::ios_base::sync_with_stdio(0);
std::cin.tie(0);
std::cout.tie(0);
std::queue<long long> q;
q.push(2);
q.push(3);
q.push(5);
q.push(7);
std::vector<long long> v;
while (!q.empty()) {
auto x = q.front();
q.pop();
v.push_back(x);
if (isPrime(x * 10 + 1)) q.push(x * 10 + 1);
if (isPrime(x * 10 + 3)) q.push(x * 10 + 3);
if (isPrime(x * 10 + 7)) q.push(x * 10 + 7);
if (isPrime(x * 10 + 9)) q.push(x * 10 + 9);
}
std::sort(v.begin(), v.end());
v.push_back(INT64_MAX);
long long a, b;
std::cin >> a >> b;
int start = 0, end = 0;
for (int i = 0; i < v.size(); i++) {
if (v[i] >= a) {
start = i;
break;
}
}
for (int i = start; i < v.size(); i++) {
if (v[i] > b) {
end = i - 1;
break;
}
}
std::cout << std::max(end - start + 1, 0) << '\n';
return 0;
}