#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
void e(vector<ll> a, vector<ll>& p){
  ll c=a.size(),d=p.size();
  for(ll bits=0; bits<d; ++bits){
    ll sum=0;
    for(int i=0; i<c; ++i){
      if(!(bits&(1<<i))) continue;
      sum+=a[i];
    }
    p[bits]=sum;
  }
  sort(p.begin(),p.end());
}
int main(void){
  ll n,t; cin>>n>>t;
  vector<ll> a(n>>1),b((n+1)>>1),p(1<<(n>>1)),q(1<<((n+1)>>1));
  for(auto& i:a) cin>>i;
  for(auto& i:b) cin>>i;
  e(a,p); e(b,q);
  ll res=0;
  for(auto& i:p){
    if(i>t) break;
    res=max(res,i+*(upper_bound(q.begin(),q.end(),t-i)-1));
  }
  cout<<res;
  return 0;
}
#include <bits/stdc++.h>
using namespace std;

using   ll  =       long long int;
using   pll =       pair<ll, ll>;
using   vll =       vector<ll>;
#define endl        "\n"
#define space       " "
#define TLE_na_ho   ios_base::sync_with_stdio(false);cin.tie(NULL)
#define MAX_SIZE    1024
#define MOD         1000000007
#define pb          push_back
#define fi          first
#define se          second
#define all(v)      v.begin(),v.end()
#define f(n)        for(ll i=0;i<n;i++)
#define rep(i,a,n)  for(ll i=a;i<n;i++)
#define repe(i,a,n) for(ll i=a;i<=n;i++)
#define repr(i,a,n) for(ll i=a;i>=n;i--)
#define ain(arr,n)  for(ll i1=0;i1<n;i1++ ) cin>>arr[i1]
#define aout(arr,n) for(ll i1=0;i1<n;i1++ ) cout<<arr[i1]<<space

ll testcases;

int main()
{
    TLE_na_ho;
    //READ THE QUESTION PROPERLY!!
    testcases = 1;
    //cin>>testcases;
    while(testcases--)
    {
        ll a, b;
        cin >> a >> b;
        ll sum = a + b;
        ll x = sum / 2;
        ll y = a - x;
        cout << x << space << y;
    }

}
