# coding: utf-8 from collections import Counter import math n,m = map(int, input().split(" ")) candys = list(map(int,input().split(" "))) while m != 0: min_ = candys.pop(candys.index(min(candys))) min_ -= 1 if min_ != 0: candys.append(min_) m -= 1 print(n - len(candys))