/*
//baekjoon 19939 : 정보올림피아드 2020 1차 초등 1번
#include<stdio.h>
#include<stdlib.h>
int main() {
int n,k;
int *arr;
scanf("%d %d",&n ,&k);
if(n <= k) {
printf("%d",-1);
return 0;
} else if (n < (((float)k)/2 * (k+1)) ) {
printf("%d",-1);
return 0;
} else {
printf("%d",(n-(int)(((float)(k-2))/2 * (k-1)))%2 == 0 ? k : k-1);
printf("%d",(n-(int)(((float)(k-2))/2 * (k-1)))%2);
return 0;
// m-!((n*2-m*m-m)%m)
}
}
*/
/*
#include<stdio.h>
int n,m;
void function(int k, int *x, int *y) {
if(k == m) {
for(int i = 0; i < m; i++) {
printf("%d ",y[i]);
}printf("\n");
return ;
}
for(int i =0; i <n; i++) {
if(x[i] != 0) {
y[k] = x[i];
x[i] = 0;
function(k+1, x, y);
x[i] = i+1;
}
x[i] = 0;
}
return ;
}
int main() {
int *arr, *y;
scanf("%d %d" ,&n ,&m);
arr = (int*)malloc(sizeof(int) * n);
y = (int*)malloc(sizeof(int) * m);
for(int i =0; i <n; i++) {
arr[i] = i+1;
if(i < m)
y[i] = 0;
}
function(0, arr, y);
}
*/
/*
#include<stdio.h>
int main() {
//문자열 생성
char s[50];
//문자열 입력 받기
scanf("%s",s);
//문자열 출력 + ??! 추가
printf("%s??!",s);
}
*/
/*
#include<stdio.h>
int main() {
int T,C;
//T 입력
scanf("%d",&T);
for(int i =0; i <T; i++) {
//C 입력
scanf("%d",&C);
//동전 개수 계산 및 출력
printf("%d %d %d %d", C/25, C%25/10, C%25%10/5, C%25%10%5/1);
}
}
*/
#include<stdio.h>
int N,M;
int Black_Jack(int *Crd,int *Slt, int Cnt) {
int Max = 0, Value;
if(Cnt == 3)
return Slt[0]+Slt[1]+Slt[2];
for(int i =0; i <N-2; i++) {
if(Crd[i] != 0) {
Slt[Cnt] = Crd[i];
//printf("%d %d\n",Crd[i],2-Cnt);
Crd[i] = 0;
/*for(int j = 0; j < N; j++){
printf("%d ",Crd[j]);
}printf("\n");*/
Value = Black_Jack(Crd, Slt, Cnt+1);
if(M-Max > M-Value) {
Max = Value;
}
}
}
return Max;
}
int main() {
int *cards,selections[3];
scanf("%d %d",&N,&M);
cards =(int*)malloc(sizeof(int) * N);
for(int i =0; i <N; i++) {
scanf("%d" ,&cards[i]);
if(i < 3)
selections[i] =0;
}
printf("%d",Black_Jack(cards, selections, 0));
}