#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<set>
#define MAXN 35
using namespace std;
/*int a[MAXN];
 bool vis[MAXN];
 int n, m, ans;
 void DFS(int st, int sum) {
 if (sum > m)
 return;
 if (ans == m)
 return;
 ans = max(ans, sum);
 int i;
 for (i = st; i < n; i++) {
 if (i > 0 && a[i] == a[i - 1] && !vis[i - 1])
 continue;
 vis[i] = true;
 DFS(i + 1, sum + a[i]);
 vis[i] = false;
 }
 }
 int main() {
 int i, s;
 while (~scanf("%d%d", &n, &m)) {
 for (s = ans = i = 0; i < n; i++) {
 scanf("%d", &a[i]);
 s += a[i];
 }
 if (s <= m) {
 printf("%d\n", s);
 continue;
 }
 sort(a, a + n);
 memset(vis, false, sizeof(vis));
 DFS(0, 0);
 printf("%d\n", ans);
 }
 return 0;
 }*/
/*
 30 10000000
 200000 300000 400000 500000 600600
 700000 80000 90000 10000 207000
 203000 220000 200000 1200000 200600
 204000 200004 520000 320000 200000
 200000 200000 200000 420000 200800
 200050 200700 2030000 520000 200080
 */
int n, m;
int a[MAXN];
set<int> myset[MAXN];
vector<int> dp[MAXN][MAXN];
void Clear() {
	int i, j;
	for (i = 0; i < MAXN; i++) {
		myset[i].clear();
		for (j = 0; j < MAXN; j++)
			dp[i][j].clear();
	}
}
int main() {
	int i, j, k, ans;
	while (~scanf("%d%d", &n, &m)) {
		Clear();
		for (i = 1; i <= n; i++)
			scanf("%d", &a[i]);
		dp[0][0].push_back(0);
		for (i = 1; i <= n; i++) {
			for (j = 1; j <= i; j++) {
				if (i - 1 >= j) {
					for (k = 0; k < dp[i - 1][j].size(); k++) {
						if (!myset[i].count(dp[i - 1][j][k])) {
							myset[i].insert(dp[i - 1][j][k]);
							dp[i][j].push_back(dp[i - 1][j][k]);
						}
					}
				}
				for (k = 0; k < dp[i - 1][j - 1].size(); k++) {
					if (dp[i - 1][j - 1][k] + a[i] <= m && !myset[i].count(dp[i
							- 1][j - 1][k] + a[i])) {
						myset[i].insert(dp[i - 1][j - 1][k] + a[i]);
						dp[i][j].push_back(dp[i - 1][j - 1][k] + a[i]);
					}
				}
			}
		}
		for (ans = i = 0; i <= n; i++) {
			for (j = 0; j <= i; j++) {
				for (k = 0; k < dp[i][j].size(); k++)
					ans = max(ans, dp[i][j][k]);
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}