var
a,b,c,d,w,i,j:longint;
f:array[1..9]of integer;
begin
assign(input,'pprime.in');
reset(input);
assign(output,'pprime.out');
rewrite(output);
readln(a,b);
if a mod 2=0 then a:=a+1;
if b>9989899 then b:=9989899;
c:=a;
while a<>0 do
begin
inc(w);
f[w]:=a mod 10;
a:=a div 10;
end;
repeat
i:=1;
for j:=1 to w div 2 do
if f[j]<>f[w+1-j] then i:=0;
if i=0 then
begin
f[1]:=f[1]+2;
c:=c+2;
if c>b then exit;
j:=1;
while f[j]>=10 do
begin
inc(f[j+1],f[j] div 10);
f[j]:=f[j] mod 10;
inc(j);
end;
if j>w then w:=j;
end;
{for j:=w downto 1 do
write(f[j]);
writeln;}
until i=1;
{writeln(c);}
while c<=b do
begin
i:=1;
for j:=2 to round(sqrt(c)) do
if c mod j=0 then i:=0;
if i=1 then
begin
for j:=w downto 1 do
write(f[j]);
writeln;
end;
i:=0;
repeat
if i=0 then
begin
f[1]:=f[1]+2;
c:=c+2;
if c>b then exit;
j:=1;
while f[j]>=10 do
begin
inc(f[j+1],f[j] div 10);
f[j]:=f[j] mod 10;
inc(j);
end;
if j>w then w:=j;
end;
i:=1;
for j:=1 to w div 2 do
if f[j]<>f[w+1-j] then i:=0;
until i=1;
end;
close(input);
close(output);
end.