# -*- coding: utf-8 -*- """ No.617 Nafmo、買い出しに行く https://yukicoder.me/problems/no/617 """ import sys from sys import stdin from itertools import compress from bisect import bisect_right input = stdin.readline def main(): N, K = map(int, input().split()) items = [] for i in range(N): items.append(int(input())) # アイテムを半分に分ける (後半は空の可能性もあり) items_a = items[:10] items_b = items[10:] # 前半のアイテムを選択した場合の重さの組み合わせを列挙 total_a = [] for i in range(2**len(items_a)): mask = [int(x) for x in list(bin(i)[2:].zfill(len(items_a)))] res = compress(items_a, mask) total_a.append(sum(res)) # 後半のアイテムを選択した場合の重さの組み合わせを列挙 total_b = [] for i in range(2**len(items_b)): mask = [int(x) for x in list(bin(i)[2:].zfill(len(items_b)))] res = compress(items_b, mask) total_b.append(sum(res)) # 前半と後半の重さの組み合わせから、K以内での最大値を求める total_a.sort(); total_b.sort(); total_max = 0; for a in total_a: i = bisect_right(total_b, K-a) total = a + total_b[i-1] if total <= K: total_max = total print(total_max) if __name__ == '__main__': main()