#pragma region 라이브러리
#include <iostream>
//#include <format>
#include <cmath>
#include <functional>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <deque>
using namespace std;
#pragma endregion
#pragma region 최적화용
#define FAST_IO() ios::sync_with_stdio(0); cin.tie(0);
#define y first
#define x second
#define INIT 9876543210
using IntPair = pair<int, int>;
using DoubleVec = vector<vector<int>>;
using Vec = vector<int>;
// 상하좌우
IntPair dir[]
{
{ 1, 0 },
{-1, 0 },
{ 0, -1 },
{ 0, 1 }
};
#pragma endregion
int main()
{
int n, m, res = 0;
cin >> n >> m;
Vec v(n);
for (int i = 0; i < n; i++)
cin >> v[i];
// 1번째
for (int i = 0; i < n; i++)
{
// 2번째
for (int j = 0; j < n; j++)
{
if (j == i)
continue;
// 3번째
for (int k = 0; k < n; k++)
{
if (k == i || k == j)
continue;
//cout << format("i = {} , j = {} , k = {}", i, j, k) << endl;
int sum = v[i] + v[j] + v[k];
if (sum <= m)
res = max(res , sum);
}
}
}
cout << res;
return 0;
}