const
fi='PRIME.INP';
fo='PRIME.OUT';
var a,b,t,d:longint;f:text;
(************************************************)
function nt(x:longint):boolean;
var h:longint;
begin
if x<2 then exit(false);
for h:=2 to trunc(sqrt(x)) do if x mod h=0 then exit(false);
exit(true);
end;
(************************************************)
function dx(x:longint):boolean;
var s,s1:string;h:longint;
begin
str(x,s);s1:='';
for h:=length(s) downto 1 do s1:=s1+s[h];
if s1=s then exit(true);
exit(false);
end;
(************************************************)
begin
assign(f,fi);reset(f);
read(f,a,b);
close(f);
assign(f,fo);rewrite(f);
d:=0;
for t:=a to b do if (dx(t)) and (nt(t)) then d:=d+1;
write(f,d);
close(f);
end.