n, k = map(int, input().split()) l = [ int(input()) for i in range(n)] l.sort(reverse=True) ans = 0 for i in l: if ans + i <= k: ans += i print(ans)