#include <bits/stdc++.h>
#define ull unsigned long long
using namespace std;
ull a, b, ile = 0;
bool prim(ull x) {
for (ull i = 2; i * i <= x; i ++)
if (x % i == 0)
return 0;
return 1;
}
void rekDokl(ull x) {
if (x > b or !prim(x))
return;
if (prim(x) and x >= a)
ile ++;
rekDokl(x * 10 + 1);
rekDokl(x * 10 + 3);
rekDokl(x * 10 + 7);
rekDokl(x * 10 + 9);
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> a >> b;
rekDokl(2);
rekDokl(3);
rekDokl(5);
rekDokl(7);
cout << ile;
}