n, k = gets.chomp.split.map(&:to_i)
arr2 = (1 .. n).to_a
arr, display = [], []
n.times{|i|
    x = gets.to_i
    arr << x
    if x == 0
        display << (i + 1) 
    else
        arr2[x - 1] = nil
    end
}
arr2.compact!
display += arr2

if k > 1
    temp = []
    arr2.each{|x|
        if arr[x - 1] != 0
            temp << [arr[x - 1], 1]
        end
    }
    temp.uniq!
    temp.each{|x, c| display << x}
    while xc = temp.pop
        x, c = xc
        if arr[x - 1] != 0 && c < k - 1
            temp << [arr[x - 1], c + 1]
            display << arr[x - 1]
        end
end
end
display.uniq!
puts display.length
