n,k=list(map(int,input().split())) now=k a=sorted([int(input()) for i in range(n)],reverse=True) index=0 min_value=min(a) while True: if min_value>now: break elif now-a[index]>=0: now-=a[index] a.pop(index) else: index+=1 print(k-now)