#include <bits/stdc++.h>
using namespace std;
int main() {
  long n, kazu;
  long tmp, goukei = 0;
  cin >> n >> kazu;
  long a[100];
  for (int i = 0; i != n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i != n; ++i) {
    for (int j = i + 1; j != n; ++j) {
      if (a[i] > a[j]) {
        tmp = a[i];
        a[i] = a[j];
        a[j] = tmp;
      }
    }
  }
  for (int i = 0; i != n; ++i) {
    if (goukei + a[i] <= kazu)
      goukei = goukei + a[i];
    else if (goukei - a[i - 1] + a[i + 1] <= kazu)
      continue;
    else
      break;
  }
  cout << goukei << endl;
}
