/**
 *    author:  orzvanh14 ( Độc cô cầu đặc )
 *    created: 23.12.2022 10:08:02
 *    too lazy to update time
**/
// i wants to take ioi
//binhtinhtutinkhongcaycunhungmotkhikhongcontutinnualatuyetvong
#include <bits/stdc++.h>

using namespace std;

#define int long long
#define nn "\n"
#define pi pair<int, int>
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define eb emplace_back
#define pb push_back
#define TASK " "

#define ms(a, x) memset(a, x, sizeof(a))
#define all(a) a.begin(), a.end()
#define All(a, n) a + 1, a + 1 + n

#define LOG 19


const int INF = 1e18;
const int mod = 1e9+7;
const int N = 1e7  + 5;
const int maxn = 1e3 + 5;
int MOD = 998244353;
int bit[200000];
struct node{
	int kc, u, hk;
	bool operator<(const node& other) const {
        return kc > other.kc; 
    }
};
struct edge{
	int v, w, h;
};
int l, r;
bool p[N];
int uoc[N];
int dem = 0;
void nhap(){
    cin >> l >> r;
}
void sang(){
	p[1] = 1;
	for(int i = 2; i < N; i++){
		if(!p[i]){
			for(int j = i; j < N; j += i){
				uoc[j]++;
				
			}
			for(int j = i * i; j < N; j += i) p[j] = 1;
		}
	}
}
bool ok(int n){
	string s = to_string(n);
	int l = 0, r = s.size() - 1;
	while(l <= r){
		if(s[l] == s[r]){
			l++;
			r--;
		}
		else return false;
	}
	return true;
}
void solve(){
	sang();
	for(int i = l; i <= r; i++){
		if(ok(i) && uoc[i] >= 3) dem++;
	}
	cout << dem << nn;
}
// 0 0 0 0 0 0 0 
signed main() {
	// freopen("WORK.INP", "r", stdin);
	// freopen("WORK.OUT", "w", stdout);
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
    nhap();
    solve();
	return 0;

}
// https://i...content-available-to-author-only...e.com/7poJyz
// https://i...content-available-to-author-only...e.com/pScgCp
// https://i...content-available-to-author-only...e.com/DFHWaU