let () = Scanf.scanf "%s\n%d\n" @@ fun n k ->
  let same = Array.make_matrix (String.length n + 1) (k + 1) 0 in
  let small = Array.make_matrix (String.length n + 1) (k + 1) 0 in
  same.(0).(0) <- 1;
  for i = 0 to String.length n - 1 do
    for j = 0 to k do
      same.(i + 1).(j) <- 
        if n.[i] = '0'
        then same.(i).(j)
        else if 0 < j then same.(i).(j - 1) else 0;
      small.(i + 1).(j) <- small.(i).(j)
        + 9 * (if j > 0 then small.(i).(j - 1) else 0)
        + max 0 (Char.code n.[i] - Char.code '1')
          * (if j > 0 then same.(i).(j - 1) else 0)
        + (if n.[i] > '0' then same.(i).(j) else 0)
    done
  done;
  Printf.printf "%d\n" @@
  same.(String.length n).(k) + small.(String.length n).(k)