#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
using namespace std;

typedef long long ll;

int a, b;
int res;
vector <int> cur;

bool Prime(const ll &x)
{
	if (x <= 1) return false;
	if (x == 2) return true;
	if (x % 2 == 0) return false;
	for (int i = 3; i * i <= x; i += 2)
		if (x % i == 0) return false;
	return true;
}

bool Add(int lvl, int nw, ll my = 0)
{
	if (lvl >= cur.size()) return Prime(my * 10 + nw);
	else return Add(lvl + 1, nw, my) && Add(lvl + 1, nw, 10 * my + cur[lvl]);
}

void Gen(ll my)
{
	if (my > b) return;
	if (a <= my) res++;
	if (Add(0, 2)) {
		cur.push_back(2); Gen(my * 10 + 2);
		cur.pop_back();
	}
	if (Add(0, 3)) {
		cur.push_back(3); Gen(my * 10 + 3);
		cur.pop_back();
	}
	if (Add(0, 5)) {
		cur.push_back(5); Gen(my * 10 + 5);
		cur.pop_back();
	}
	if (Add(0, 7)) {
		cur.push_back(7); Gen(my * 10 + 7);
		cur.pop_back();
	}
}

int main()
{
	scanf("%d %d", &a, &b);
	Gen(0);
	printf("%d\n", res);
	return 0;
}