n, k = map(int, input().split()) l = [int(input()) for i in range(n)] ans = 0 def f(i, now): global ans if i >= len(l): if now > ans and now <= k: ans = now return if now > k: return if now > ans: ans = now f(i+1, now+l[i]) f(i+1, now) f(0, 0) print(ans)