var
  s:string;
  t,len:longint;   ans:int64;
function get1(x,y:longint):int64;
begin                   //y=head
  exit((x-1)*9+y);
end;
function get2_1(x:longint):int64;
begin
  exit((x-2)*(x-1) div 2*81);
end;
function get2_2(x,y:longint):int64;
begin
  exit((x-1)*y*9);
end;
function get3(x:longint):int64;
begin
  exit((x-3)*(x-2)*(x-1) div 6*729);
end;

begin
  readln(s);
  len:=length(s);
  readln(t);
  if (t=1) then
  begin
    writeln(get1(len,ord(s[1])-48));
  end else if (t=2) then begin
    ans:=get2_1(len)+get2_2(len,ord(s[1])-49)+get1(len-1,ord(s[2])-48);
    writeln(ans);
  end else begin
    ans:=get2_1(len-1)+get2_2(len-1,ord(s[2])-49)+get1(len-2,ord(s[3])-48)+get3(len);
    ans:=ans+(len-1)*(len-2) div 2*81*(ord(s[1])-49);
    writeln(ans);
  end;
end.