#include <iostream>
using namespace std;
int main() {
int n, m;
cin >> n>> m;
int card[100];
for (int i = 0; i < n; i++)
cin >> card[i];
int sum = 0;
int temp = 0;
int result = 0;
for (int i = 0; i < n - 2; i++) {
for (int j = 1; j < n - 1; j++) {
for (int k = 2; k < n; k++) {
sum = card[i] + card[j] + card[k];
if (sum <= m) {
temp = sum;
if (temp > result)
result = temp;
}
}
}
}
cout << result;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwppbnQgbWFpbigpIHsKICAgICAgICBpbnQgbiwgbTsKICAgICAgICBjaW4gPj4gbj4+IG07CiAgICAgICAgaW50IGNhcmRbMTAwXTsKICAgICAgICBmb3IgKGludCBpID0gMDsgaSA8IG47IGkrKykKICAgICAgICAgICAgICAgY2luID4+IGNhcmRbaV07CiAgICAgICAgaW50IHN1bSA9IDA7CiAgICAgICAgaW50IHRlbXAgPSAwOwogICAgICAgIGludCByZXN1bHQgPSAwOwogICAgICAgIGZvciAoaW50IGkgPSAwOyBpIDwgbiAtIDI7IGkrKykgewogICAgICAgICAgICAgICBmb3IgKGludCBqID0gMTsgaiA8IG4gLSAxOyBqKyspIHsKICAgICAgICAgICAgICAgICAgICAgICBmb3IgKGludCBrID0gMjsgayA8IG47IGsrKykgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzdW0gPSBjYXJkW2ldICsgY2FyZFtqXSArIGNhcmRba107CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChzdW0gPD0gbSkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHRlbXAgPSBzdW07CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHRlbXAgPiByZXN1bHQpCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJlc3VsdCA9IHRlbXA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgY291dCA8PCByZXN1bHQ7Cn0=