{
zadatak: proizvod
jezik: pascal
}
program proizvod;
var fin,fou:text;
		m,n,i,j,pom,st,pom2,st2,broj,stk:longint;
		count:array[1..2] of longint;
		a:array[1..100000] of byte;
		c1,c2:array[1..50005] of byte;
		{cifre,jos1,jos2:array[1..8] of byte;}
		pr:byte;
		c:char;

procedure sortiraj;
var brc:array[0..9] of longint;
		iter:integer;
		z:byte;
begin
	for i:=0 to 9 do brc[i]:=0;
	for i:=1 to n do inc(brc[a[i]]);
	iter:=9;
	for i:=1 to n do begin
		while brc[iter]=0 do dec(iter); a[i]:=iter; dec(brc[iter]);
	end;
end;

procedure dodeli;
begin
	for i:=2 to n do begin
	 if count[1]<count[2] then begin
		 inc(count[1]); c1[count[1]]:=a[i];
	 end
	else if count[2]<count[1] then begin
			 inc(count[2]); c2[count[2]]:=a[i];
		 end
	else if (pr=1) or ((pr=0) and (c1[count[1]]=c2[count[2]])) then begin
			 inc(count[1]); c1[count[1]]:=a[i]; end
	else if (pr=2) then begin
			 inc(count[2]); c2[count[2]]:=a[i];
		 end
	else if c1[count[1]]<c2[count[2]] then begin
		inc(count[1]); c1[count[1]]:=a[i]; pr:=1; end
	else if c1[count[1]]>c2[count[2]] then begin
		inc(count[2]); c2[count[2]]:=a[i]; pr:=2; end
	end;
end;

begin
	assign(fin,'proizvod.in'); reset(fin);
	assign(fou,'proizvod.out'); rewrite(fou);
	readln(fin,n,m);
	for i:=1 to n do begin read(fin,c); a[i]:=ord(c)-48 end;
	sortiraj;
	pr:=0; count[1]:=1; count[2]:=0; c1[1]:=a[1];
	dodeli;

{	if count[1]>=8 then for i:=count[1]-7 to count[i] do begin     															inc(j); jos1[j]:=c1[i];
 end
	else }

{	pom:=c1[count[1]]*c2[count[2]]; cifre[8]:=pom mod 10; prenosi}
	st:=1; pom:=0; i:=count[1]; j:=count[2];
		while (i>0) and (i>count[1]-m) do begin
			 pom:=pom+st*c1[i]; st:=st*10; dec(i);
		end;

	st:=1; for i:=1 to m do st:=st*10; st2:=1; stk:=st;

	j:=count[2]; broj:=0;
	while (j>0) and (j>count[2]-m) do begin
		pom2:=(c2[j]*pom) mod st;
		st:=st div 10;
		dec(j);
		broj:=pom2*st2+broj;
		st2:=st2*10;
	end;

	write(fou,broj mod stk);
{	for i:=9-m to 8 do write(fou,cifre[i]);}
	close(fin); close(fou);
end.
