program almost_everywhere_zero
  implicit none
  integer :: k, n, d, dp(0:1,0:100,0:4) = 0, i, j, l, m, u
  character(100) :: s
  read(*,'(a)') s
  read(*,*) k
  n = len_trim(s)
  dp(1,0,0) = 1
  do i = 1, n
    d = ichar(s(i:i))-48
    do j = 0, 1
      u = merge(d,9,j == 1)
      do l = 0, u
        do m = 0, k
          dp(merge(merge(1,0,l == d),0,j == 1),i,merge(m+1,m,l > 0)) = &
          & dp(merge(merge(1,0,l == d),0,j == 1),i,merge(m+1,m,l > 0))+dp(j,i-1,m)
        end do
      end do
    end do
  end do
  write(*,'(i0)') sum(dp(:,n,k))
end program almost_everywhere_zero