{
TASK:rprimes
LANG:PASCAL
}
var  a:array[1..50000000] of shortint;
var b:array[1..50000000] of shortint;
var m,n,i,j,k,l,v,pr,aa,br:longint;
label c,cc,jj,yy,yyy,jjj;
begin
readln(m,n);
br:=0;
for i:=1 to 50000000 do
begin
a[i]:=0;
b[i]:=0;
end;
v:=0;i:=1;
a[1]:=-1;
while (v=0) do
begin
 if i>n then goto c;
   if (i<=50000000) and (a[i]=-1) then goto cc;
   if (i>50000000) and (b[i-50000000]=-1) then goto cc;
   if i<=50000000 then
    begin
     if a[i]<>-1 then
      begin
       for j:=i+1 to n do
        begin
        if j mod i=0 then
         begin
          if j>50000000 then b[j-50000000]:=-1
          else a[j]:=-1;
         end;
        end;
       end;
     end;
  if i>50000000 then
    begin
     if b[i-50000000]<>-1 then
      begin
      for j:=i+1 to n do
         begin
         if j mod i=0 then
         begin
          if j>50000000 then b[j-5000000]:=-1
          else a[j]:=-1;
         end;
         end;
      end;
     end;
cc:i:=i+1;
end;
c:for i:=m to n do
begin
if i<=50000000 then
begin
pr:=1;
if a[i]=-1 then pr:=0;
if a[i]<>-1 then
begin
aa:=i;
jj:aa:=aa div 10;
if aa=0 then goto yy;
if a[aa]=-1 then pr:=0;
goto jj;
end;
yy:if pr=1 then br:=br+1;
end;
end;
if i>50000000 then
begin
pr:=1;
if b[i-50000000]=-1 then pr:=0;
if b[i-50000000]<>-1 then
begin
aa:=i;
jjj:aa:=aa div 10;
if aa=0 then goto yyy;
if aa>50000000 then
begin
if b[aa-50000000]=-1 then pr:=0;
goto jjj;
end;
if aa<=50000000 then
begin
if a[aa]=-1 then pr:=0;
goto jjj;
end;
end;
yyy:if pr=1 then br:=br+1;
end;
write(br);
end.
