program main
  implicit none
  character(100) :: n2, n, n3
  character(1) :: c
  integer :: k, l, i1, i2, i3, j1, j2, j3, res
  read *, n2
  n3 = "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
  n = n3
  l = len(trim(n2))
  n(100-l+1:100) = trim(n2)
  read *, k
  res = 0
  if (k == 1) then
    do i1 = 1, 100
      do j1 = 1, 9
        n2 = n3
        write (c, "(i0)") j1
        n2(i1:i1) = c(1:1)
        if (n2 <= n) res = res + 1
      end do
    end do
  else if (k == 2) then
    do i1 = 1, 100
      do i2 = i1 + 1, 100
        do j1 = 1, 9
          do j2 = 1, 9
            n2 = n3
            write (c, "(i0)") j1
            n2(i1:i1) = c(1:1)
            write (c, "(i0)") j2
            n2(i2:i2) = c(1:1)
            if (n2 <= n) res = res + 1
          end do
        end do
      end do
    end do
  else
    do i1 = 1, 100
      do i2 = i1 + 1, 100
        do i3 = i2 + 1, 100
          if (i1 == 100 - l + 1) then
            do j1 = 1, 9
              do j2 = 1, 9
                do j3 = 1, 9
                  n2 = n3
                  write (c, "(i0)") j1
                  n2(i1:i1) = c(1:1)
                  write (c, "(i0)") j2
                  n2(i2:i2) = c(1:1)
                  write (c, "(i0)") j3
                  n2(i3:i3) = c(1:1)
                  if (n2 <= n) res = res + 1
                end do
              end do
            end do
          else if (i1 > 100 - l + 1) then
            res = res + 9 * 9 * 9
          end if
        end do
      end do
    end do
  end if
  print "(i0)", res
end program main
