package main

import (
	"fmt"
	"strconv"
)

func main() {
	var n []byte
	fmt.Scan(&n)
	ns := make([]int, len(n))
	for i := range n {
		ns[i], _ = strconv.Atoi(string([]byte{n[i]}))
	}

	var k int
	fmt.Scan(&k)
	var ans int
	for i := 1; i <= len(ns)-1; i++ {
		if i < k {
			continue
		}
		ans += comb(i-1, k-1) * pow(9, k)
	}
	for i := 1; i < ns[0]; i++ {
		ans += comb(len(ns)-1, k-1) * pow(9, k-1)
	}

	ps := make([]int, len(ns))
	mode := 0
	var zi, zj int
	for i := 1; i < len(ns); i++ {
		if mode == 0 {
			if ns[i] == 0 {
				ps[i] = 0
				continue
			}
			ps[i] = ns[i]
			zi = i
			mode++
		} else {
			ps[i] = 9
			if mode == 1 {
				if ns[i] == 0 {
					continue
				}
				zj = i
				mode++
			}
		}
	}

	switch k {
	case 1:
		ans++
	case 2:
		for i := 1; i < len(ps); i++ {
			ans += ps[i]
		}
	case 3:
		for i := 1; i < len(ps)-1; i++ {
			for j := i + 1; j < len(ps); j++ {
				ans += ps[i] * ps[j]
				if i == zi && j == zj {
					ans -= (9 - ns[j])
				}
			}
		}
	}

	fmt.Println(ans)
}

func pow(a, b int) int {
	r := 1
	for i := 0; i < b; i++ {
		r *= a
	}
	return r
}

func comb(a, b int) int {
	switch b {
	case 0:
		return 1
	case 1:
		return a
	case 2:
		return a * (a - 1) / 2
	}
	return 0
}
