n, m = gets.split.map(&:to_i) box = gets.split.map(&:to_i) count = 0 empty_box = 0 while m > count if box.min > 0 box[box.index(box.min)] -= 1 count += 1 if box.min == 0 box.delete_at(box.index(box.min)) empty_box += 1 end break if count == m end end puts empty_box