#include <iostream>
#include <cstdio>

using namespace std;

int freq[15];
long long nr;
int cif[] = {0, 2, 3, 5, 7};
int sol[20];
int lg;
int ans;
long long a, b;

int isPrime(int nr) {
    if(nr == 0 || nr == 1) {
        return 0;
    }

    for(int i = 2; i * i <= nr; ++i) {
        if(nr % i == 0) {
            return 0;
        }
    }

    return 1;
}

void bkt(int pos) {
    if(pos == lg + 1) {
        int flag = 0;
        for(int j = 1; j < (1 << lg); j++) {
            int pw = 0;
            for(int bit = 1, poss = 1; bit <= lg; bit <<= 1, poss++) {
                if(bit & j) {
                    pw = pw * 10 + sol[poss];
                }
            }

            if(isPrime(pw) == 0) {
                flag = 1;
                break;
            }
        }

        if(flag == 0) {
            if(a <= 1LL * nr && 1LL * nr <= b) {
                ++ans;
            }
        }
    }
    else {
        for(int i = 1; i <= 4; ++i) {
            if(freq[i] == 0) {
                nr = nr * 10 + cif[i];
                sol[pos] = cif[i];
                bkt(pos + 1);
                nr /= 10;
                sol[pos] = 0;
            }
        }
    }
}

int main() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    #endif // ONLINE_JUDGE

    cin >> a >> b;

    for(lg = 1; lg <= 4; lg++) {
        bkt(1);
    }

    cout << ans << '\n';

    return 0;
}