N, K = map(int, input().split()) a = [] rec = 0 for i in range(N): s = int(input()) if s <= K: a.append(s) rec += s if rec <= K: print(rec) else: num = 0 for i in range(1 << N): sum = 0 for j in range(N): if ((1 << j) & i) != 0: sum += a[j] if sum > K: sum -= a[j] break num = max(sum, num) print(num)