import itertools import heapq N, K = map(int, input().split()) A = list(map(int, input().split())) def make(A): N = len(A) res = [] for X in itertools.product((True, False), repeat=N): t = 0 for a, x in zip(A, X): if x: t += a res.append(t) return res X = make(A[:N//2]) Y = make(A[N//2:]) X.sort(reverse=True) Y.sort(reverse=True) lx = len(X) ly = len(Y) used = set() hq = [(-(X[0]+Y[0]), 0, 0)] used.add((0, 0)) for _ in range(K): p, x, y = heapq.heappop(hq) if x+1 < lx and not (x+1, y) in used: heapq.heappush(hq, (-(X[x+1] + Y[y]), x+1, y)) used.add((x+1, y)) if y+1 < ly and not (x, y+1) in used: heapq.heappush(hq, (-(X[x] + Y[y+1]), x, y+1)) used.add((x, y+1)) print(-p)