#include <bits/stdc++.h>
using namespace std;
const int a[4]={2,3,5,7};
int i,j,k,e,A,B,x,y,z,b[22],r;
set<int> q,w;
bool prime(int x) {
  for (int i=2; i*i<=x; i++) if (x%i==0) return false;
  return true;
}
int main() {
  scanf("%d%d",&A,&B);
  for (i=0; i<4; i++) q.insert(a[i]);
  while (!q.empty()) {
    x=*q.begin();
    w.insert(x);
    q.erase(q.begin());
    if (x>=A && x<=B) r++;
    if (x>B/10) continue;
    for (i=0; i<4; i++) {
      y=x*10+a[i];
      if (q.count(y) || w.count(y)) continue;
      if (!prime(y)) continue;
      for (j=0, z=y; z>0; z/=10, j++) b[j]=z%10;
      for (k=j-1; k>=0; k--) {
        z=0;
        for (e=j-1; e>=0; e--) if (e!=k) z=z*10+a[e];
        if (!q.count(z) && !w.count(z)) break;
      }
      if (k<0) q.insert(y);
    }
  }
  printf("%d\n",r);
  return 0;
}