import Data.List
import Data.List.Split
import qualified Data.Vector as V
main = mapM_ (print . solve) . chunksOf 2 . map (map read. words) . lines =<< getContents
solve::[[Int]]->Int
solve [[n,k],as] = fst $ dfs 0 0 where
  vas = V.fromList . map (\a->if a==1 then 0 else 1) $ as
  g = V.accum (flip (:)) (V.replicate n []) . flip zip [1..] . map (subtract 1) . tail $ as
  dfs r v
    |v==0 || m==0 = (c+vas V.! v,k-1)
    |otherwise = (c,m-1)
    where 
      cs = map (dfs (r+1)) (g V.! v)
      c = foldl' (+) 0 . map fst $ cs
      m = foldl' (min) (k-1) . map snd $ cs