{
TASK:rprimes
LANG:PASCAL
}
program primes;
var a,b,i,s,h,j,n:longint;
    d,w,e:integer;
    x:boolean;
begin
 readln(a,b);
 s:=0;
 for i:=a to b do begin
  x:=true;
   n:=i-1;
  for j:=2 to n do
   if (i mod j=0) then x:=false;
  if x then begin
   h:=i;
   while ((h div 10>0) and x ) do begin
    h:=h div 10;
   n:=h-1;
  for j:=2 to n do
   if (h mod j=0) then x:=false;
   end;
  end;
  if (x and (h<>1)) then s:=s+1;
 end;
writeln(s);

end.