#include <iostream>
#include <algorithm>
using namespace std;

int main() {
  while(1) {
    int n, m, a[1000]={},check=0,max=0,v[1000000]={},k=0;
    cin >> n >> m;
    if(n==0&&m==0) break;

    for(int i=1; i<=n; i++) cin >> a[i];
    for(int i=0; i<=n; i++) {
      for(int j=i; j<=n; j++) {
	v[k]=a[i]+a[j];
	k++;
      }
    }
    sort(v, v+k);

    for(int i=0; i<k; i++){
      if (v[i]>m) break;      
      int t=distance(v,upper_bound(v, v+k, m-v[i]));
      if(v[i]+v[t]<=m && max<v[i]+v[t]) max = v[i]+v[t];
      if(t+1<k && v[i]+v[t+1]<=m && max<v[i]+v[t+1]) max = v[i]+v[t+1];
      if(t-1>=0 && v[i]+v[t-1]<=m && max<v[i]+v[t-1]) max = v[i]+v[t-1];
    }
    cout << max << endl;
  }
  return 0;
}
