import sys input = sys.stdin.readline from collections import * N, M = map(int, input().split()) A = list(map(int, input().split())) A.sort(reverse=True) dp = defaultdict(int) dp[0] = 0 for Ai in A: ndp = defaultdict(int) for k in dp: ndp[k] = max(ndp[k], dp[k]) if k>0: ndp[-(k-Ai)] = max(ndp[-(k-Ai)], dp[k]) else: ndp[-k+Ai] = max(ndp[-k+Ai], dp[k]+Ai) dp = ndp ans = 0 for k in dp: if -M<=k<=0: ans = max(ans, dp[k]) print(ans)