object Main extends App {
	val sc = new java.util.Scanner(System.in)
	val pw = new java.io.PrintWriter(System.out)
	
	val n = sc.next
	val k = sc.nextInt
	val d = n.size - 1
	
	pw.println((if (d < k) 0 else d * Math.pow(Math.pow(9, k), k)).toInt +
			   (1 to k).map(i => (n(i-1).asDigit - 1) * Math.pow(9, k - i)).sum.toInt + 1)
	pw.flush()
}