#include <bits/stdc++.h>
using namespace std;
int n, c, ans;
int a[101], b[101], sum[101];
void search(int s, int tot){
if (tot > c) return;
if (tot + sum[s] < ans) return;
if (tot > ans) ans = tot;
if (ans == c) return;
for (int i = s; i <= n; i++){
search(i + 1, tot + a[i]);
}
}
int main(){
cin >> n >> c;
for (int i = 1; i <= n; i++)
cin >> a[i];
for (int i = n; i > 0; i--)
sum[i] = sum[i + 1] + a[i];
if (sum[1] > c) search(1, 0);
else ans = sum[1];
cout << ans << endl;
return 0;
}