#include <algorithm>
#include <iostream>
#include <functional>
using namespace std;
using ll = long long;

const int MAXN = 40, MAXH = 20;
int n, lim, p1, p2;
ll t, a[MAXN], s1[1 << MAXH], s2[1 << MAXH];

void dfs1(int cur, ll sum) {
  if (cur == lim) {
    s1[p1++] = sum;
    return;
  }
  dfs1(cur + 1, sum);
  dfs1(cur + 1, sum + a[cur]);
}

void dfs2(int cur, ll sum) {
  if (cur == n) {
    s2[p2++] = sum;
    return;
  }
  dfs2(cur + 1, sum);
  dfs2(cur + 1, sum + a[cur]);
}

int main() {
  cin >> n >> t;
  for (int i = 0; i < n; i++) cin >> a[i];
  lim = n / 2;
  dfs1(0, 0);
  dfs2(lim, 0);
  sort(s1, s1 + p1);
  sort(s2, s2 + p2, greater<ll>());
  ll ans = 0;
  for (int i = 0, j = 0; i < p1; i++) {
    while (j < p2 && s1[i] + s2[j] > t) j++;
    if (j < p2) ans = max(ans, s1[i] + s2[j]);
  }
  cout << ans << endl;
}

#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
const long long mod = 1e9+7;
//////////////////////////////////

int main() {
  int h, w; cin >> h >> w;
  vector<vector<int>> a(h, vector<int>(w));
  int mn = 1e9;
  for(int i=0; i<h; i++) for(int j=0; j<w; j++) {
    cin >> a[i][j];
    mn = min(mn, a[i][j]);
  }

  int ans = 0;
  for(int i=0; i<h; i++) {
    for(int j=0; j<w; j++) {
      ans += a[i][j] - mn;
    }
  }
  cout << ans << endl;


  return 0;
}

// EOF