uses crt;
var s,h,n : int64;
j: integer;
function snt( x : integer) : boolean;
var a,i : integer;
begin a:=0;
for i:=1 to x do if x mod i=0 then a:=a+1;
if a=2 then snt:=true else snt:=false; end;
function docao(d : integer) : integer;
var m,tong : integer;
begin tong :=0; m:=d;
while m>0 do begin
tong:=tong+m mod 10;
m:=m div 10; end;
docao:=tong; end;
begin clrscr;
assign(input,'DOCAO.INP');
assign(output,'DOCAO.OUT');
reset(input);
rewrite(output);
read(input,n,h);
for j:=1 to n do if (snt(j)=true) and (docao(j)=h) then writeln(output,j);
close(input);
close(output);
readln
end.