#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cassert>
#include <ctime>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <deque>
#include <queue>
#include <sstream>
#include <iostream>
#include <algorithm>

using namespace std;

#define pb push_back
#define mp make_pair
#define fs first
#define sc second

const double pi = acos(-1.0);
const int size = 500;

bool could[size][size][size];

int main() {
    freopen("fence.in", "r", stdin);
    freopen("fence.out", "w", stdout);

    int n;
    int k;
    cin >> n >> k;
    vector <int> wishes;
    for (int i = 0; i < n; i++) {
    	int val;
    	cin >> val;
    	wishes.push_back(val);
    }
    int ans = 0;
    vector <int> p;
    for (int i = 0; i < n; i++)
    	p.push_back(i);
   	do {
	   	for (int i = 0; i <= n; i++)
	   		for (int j = 0; j <= k; j++)
	   			for (int q = 0; q <= k; q++)
	   				could[i][j][q] = (i == 0 && j == 0);
	    for (int i = 0; i < n; i++) {
    		int val = wishes[p[i]];
    		for (int j = 0; j <= k; j++)
    			for (int q = 0; q <= k; q++)
    				if (could[i][j][q]) {
    					for (int h = max(0, val - j); h <= val; h++)
    						if (j + h <= k)
    							could[i + 1][j + h][min(q, h)] = true;
    				}	
    	
    	}
   	    for (int i = 0; i <= k; i++)
	    	for (int j = 0; j <= k; j++)
    			if (could[n][i][j])
    				ans = max(ans, j);
   	} while (next_permutation(p.begin(), p.end()));

   	cout << ans << endl;
    
   	return 0;
}