#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int card[101];
vector<int> idx;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m;
int max = 0;
cin >> n >> m;
for (int i = 0; i < n; i++)
{
cin >> card[i];
if (i < 3)
idx.push_back(1);
else
idx.push_back(0);
}
sort(idx.begin(), idx.end());
do
{
int total = 0;
for (int i = 0; i < idx.size(); i++)
{
if (idx[i] == 1)
{
total += card[i];
}
}
if (max < total && total <= m)
max = total;
} while (next_permutation(idx.begin(), idx.end()));
cout << max << "\n";
return 0;
}