#include<bits/stdc++.h>
using namespace std;
#define int long long

bool check_prime(int n){
    if(n < 2) return false;
    for(int i = 2; i*i <= n; i++){
        if(n % i == 0) return false;
    }
    return true;
}
signed main(){

    queue<int> q;
    q.push(2);
    q.push(3);
    q.push(5);
    q.push(7);
    
    vector<int> a;
    while(!q.empty()){
        int x = q.front();
        // a.push_back(x);
        q.pop();
        if(x >=1e13-1){
            // cout << x << "\n";
            continue;
        }
        else{
            int newx = x*10;
            for(int i = 1; i <= 9; i+=2){
                if(check_prime(newx + i)){
                    a.push_back(newx + i);
                    // cout << "as";
                    q.push(newx + i);
                }
            }
        }

    }
    int x,y;
    cin >> x >> y;
    sort(a.begin(), a.end());
    auto it1 = lower_bound(a.begin(), a.end(), x);
    auto it2 = upper_bound(a.begin(), a.end(), y);
    int ans = max(0LL, (int)(it2 - it1));
    cout << ans;
    // for(int i : a){
    //     cout << i << " ";
    // }
    return 0;
}
