{
TASK:rprimes
LANG:PASCAL
}

program rprimes;
var  m,i,x,y:integer;
     b:array[1..20000]of byte;
  function IsProsto(a:integer): boolean;
   var n,i:integer;
   begin
    i:=0;
     while a>10 do
       begin
        inc(i);
        b[i]:=(a div 10);
        a:=(a mod 10);
       end;
    n:=i+1;
    b[n]:=a;
     if (a=1)or(a=4)or(a=6)or(a=8) then
       isprosto:=false
     else
       for i:=1 to n do
        if (b[i]=2)or(b[i]=4)or(b[i]=5)or(b[i]=6)or(b[i]=8) then
          isprosto:=false
        else
          isprosto:=true;
  end;
begin
  read(x,y);
  m:=0;
  for i:=x to y do
   if isprosto(i)and(i mod 3>0)and(i mod 10>0)and(i mod 7>0) then
      inc(m);
write(m);
end.





