n,k=list(map(int,input().split())) A=sorted([int(input()) for i in range(n)],reverse=True) w=0 for a in A: if w+a<=k: w+=a print(w)