import strutils, sequtils, algorithm let NM, C0 = stdin.readLine.split.map parseInt var C = C0 C.sort(cmp) for i in 0 ..< NM[1]: C[0] -= 1 if C[0] == 0: C.delete(0) echo C0.len - C.len