package main

import (
  "bufio"
  "os"
  "strconv"
  "strings"
  "fmt"
)

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  buffer := make([]byte, 0)
  for true {
    line, isPrefix, err := reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func NextInt(A ...*int) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.Atoi(L[i])
  }
}
func NextIntVec(A *[]int) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]int, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.Atoi(l)
  }
}
func NextFloat(A ...*float64) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.ParseFloat(L[i], 64)
  }
}
func NextFloatVec(A *[]float64) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]float64, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.ParseFloat(l, 64)
  }
}
func Write(s interface{}) {
  fmt.Fprintln(writer, s)
}
func WriteIntVec(A []int) {
  S := make([]string, len(A))
  for i, a := range A {
    S[i] = strconv.Itoa(a)
  }
  Write(strings.Join(S, " "))
}
func Output() {
  _ = writer.Flush()
}

func Solve() {
  N := NextLine()
  var K int
  NextInt(&K)
  L := len(N)
  ans := 0
  C := make([][]int, len(N))
  for i := range C {
    C[i] = make([]int, 4)
    C[i][0] = 1
    C[i][1] = 9 * (L - 1 - i)
    C[i][2] = 81 * (L - 1 - i) * (L - 2 - i) / 2
    C[i][3] = 729 * (L - 1 - i) * (L - 2 - i) * (L - 3 - i) / 6
  }
  fixed := 0
  for i, s := range N {
    n := int(s) - int('0')
    if K < fixed { continue }
    ans += C[i][K - fixed]
    if fixed < K && 0 < n { ans += (n - 1) * C[i][K - fixed - 1] }
    fixed++
  }
  if fixed == K { ans++ }
  Write(ans)
  return
}

func main() {
  Solve()
  Output()
}