#coding:utf-8 from heapq import heapify,heappop,heappush N,M=map(int,raw_input().split()) C=map(int,raw_input().split()) C1=C heapify(C) cnt=0 while M: s=heappop(C) s-=1 M-=1 if s!=0: heappush(C,s) else: cnt+=1 print cnt