#include <bits/stdc++.h>
#define ll long long
#define endl "\n"
#define F first
#define S second
#define loop(a,n) for(int i=a; i<=n ; i++)
#define TIME (1.0 * clock() / CLOCKS_PER_SEC)
#define NAME "sieungto"
using namespace std;
ll a, b, res;
bool check(ll n) {
    if (n < 2) return false;
    if (n == 2 || n == 3) return true;
    if (n % 2 == 0) return false;
    for (ll i = 3; i * i <= n; i += 2)
        if (n % i == 0) return false;
    return true;
}

ll solve(ll a, ll b) {
    queue<ll> q;
    q.push(2); q.push(3); q.push(5); q.push(7);
    ll d = 0;
    while (!q.empty()) {
        ll h = q.front();
        q.pop();
        if (h >= a && h <= b)
            d++;
        if (h > b / 10) continue;
        int dg[] = {1, 3, 7, 9};
        for (int i = 0; i < 4; i++) {
            ll next = h * 10 + dg[i];
            if (check(next)) {
                q.push(next);
            }
        }
    }
    return d;
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    freopen(NAME".INP", "r", stdin);
    freopen(NAME".OUT", "w", stdout);
    while (cin >> a >> b) {
        res += solve(a, b);
    }

    cout << res;
    //cout << "Time: " << TIME << "s\n";
    return 0;
}
