var
k,m,i,j:longint;
mods,now,pre,outit:array[1..1000000] of longint;
head,tail,mid:longint;//三指针
hash:array[0..9,0..1000]of boolean;
procedure out(t:longint);
var k,l:longint;
begin
k:=0;
repeat
inc(k);
outit[k]:=now[t];
if pre[t]=0 then break
else t:=pre[t];
until false;
for l:=k downto 1 do write(outit[l]);
writeln;
close(output);
halt;
end;
begin
assign(input,'sramoc.in');
reset(input);
assign(output,'sramoc.out');
rewrite(output);
readln(k,m);
close(input);
head:=0;tail:=k-1;mid:=k-1;
fillchar(hash,sizeof(hash),false);
for i:=1 to k-1 do
begin
mods[i]:=i;
now[i]:=i;
pre[i]:=0;
end;//初始化
repeat
for i:=head+1 to tail do
for j:=0 to k-1 do
begin
inc(mid);
now[mid]:=j;
pre[mid]:=i;
mods[mid]:=((mods[i] mod m)*(10 mod m)+(j mod m)) mod m;
if mods[mid]=0 then out(mid);
if hash[now[mid],mods[mid]] then dec(mid)
else hash[now[mid],mods[mid]]:=true;
end;//入队
head:=tail;
tail:=mid;
until false;
end.