program zzn;
type
arr=array[0..255]of integer;
var
k,m,i,j:longint;
st:string;
a,b:arr;
procedure init;
begin
assign(input,'sramoc.in');
reset(input);
assign(output,'sramoc.out');
rewrite(output);
readln(k,m);
end;
procedure closef;
begin
close(input);
close(output);
end;
function can(x:arr):boolean;
var
i:integer;
begin
for i:=1 to x[0] do
if x[i]>k-1 then exit(false);
exit(true);
end;
procedure mul(a:arr;x:longint);
var
i:integer;
begin
fillchar(b,sizeof(b),0);
for i:=1 to a[0] do
begin
b[i]:=b[i]+a[i]*x;
b[i+1]:=b[i] div 10;
b[i]:=b[i] mod 10;
end;
b[0]:=a[0]+1;
while b[b[0]]>=10 do
begin
b[b[0]+1]:=b[b[0]]div 10;
b[b[0]]:=b[b[0]]mod 10;
inc(b[0]);
end;
if b[b[0]]=0 then dec(b[0]);
end;
procedure main;
begin
i:=1;
fillchar(a,sizeof(a),0);
str(m,st);
a[0]:=length(st);
for i:=1 to a[0] do a[i]:=ord(st[a[0]+1-i])-48;
while true do
begin
mul(a,i);
if can(b) then
begin
for j:=b[0] downto 1 do write(b[j]);writeln;
break;
end else inc(i);
end;
end;
begin
init;
main;
closef;
end.