var n,d,d_nt,dem,j:byte;
i,s:longint;
f:text;
const fi='DUALPAL.INP';
fo='DUALPAL.OUT';
function dx(n:qword):boolean;
var st:string;
i:byte;
begin
str(n,st);
for i:=1 to length(st) div 2 do
if st[i]<>st[length(st)-i+1] then
exit(false);
exit(true);
end;
function doi(n:longint;hs:byte):boolean;
var a,lt:qword;
begin
a:=0;lt:=1;
while n<>0 do
begin
a:=a+(n mod hs)*lt;
n:=n div hs;
lt:=lt*10;
end;
if dx(a)=true then exit(true);
exit(false);
end;
function nt(n:longint):boolean;
var i:longint;
begin
for i:=2 to trunc(sqrt(n)) do
if n mod i = 0 then exit(false);
exit(true);
end;
begin
assign(f,fi);reset(f);
readln(f,n,s);
close(f);
assign(f,fo);rewrite(f);
d:=0;
d_nt:=0;
i:=s+1;
while d<>n do
begin
dem:=0;
for j:=2 to 10 do
if doi(i,j)=true then
inc(dem);
if dem>=2 then
begin
if nt(i)=true then inc(d_nt);
inc(d);
writeln(f,i);
end;
inc(i);
end;
writeln(f,d_nt);
close(f);
end.