#include<bits/stdc++.h>
#define pb push_back
#define ll long long int
using namespace std;
int main()
{
   ll i,j,k,T,c=0,n;
   cin>>n>>T;
   ll arr[n];
   for(i=0;i<n;i++)
   {
       cin>>arr[i];
   }



  vector<ll>vec1,vec2,vec3;

   for(i=0;i<n/2;i++)
   {
       vec1.pb(arr[i]);
   }

   for(i=n/2;i<n;i++)
   {
       vec2.pb(arr[i]);
   }


   n=vec1.size();

   ll ans=0;

   for(i=0;i<(1LL<<n);i++)
   {
      c=0;
      for(j=0;j<n;j++)
      {
        if(i&(1LL<<j))
        {
           c+=vec1[j];
        }
      }

      if(c<=T)
      {
       vec3.pb(c);
      }
   }

   sort(vec3.begin(),vec3.end());
   ans=vec3[vec3.size()-1];
   c=0;

   n=vec2.size();

   for(i=0;i<(1LL<<n);i++)
   {
      c=0;
      for(j=0;j<n;j++)
      {
        if(i&(1LL<<j))
        {
           c+=vec2[j];
        }
      }

        ll id=lower_bound(vec3.begin(),vec3.end(),T-c)-vec3.begin();
          if(c<=T)
          ans=max(ans,c);

           if(id==vec3.size())
            ans=max(ans,c+vec3[id-1]);
          else if(vec3[id]==T-c)
            ans=max(ans,T);
          else if(id>0)
            ans=max(ans,c+vec3[id-1]);
      }


   cout<<ans;




return 0;

}

#include<bits/stdc++.h>
#define re register
#define ll long long
#define dl double
#define LL inline ll
#define I inline int
#define V inline void
#define B inline bool
#define FOR(i,a,b) for(re int i=(a),i##i=(b) ; i<=i##i ; ++i)
#define ROF(i,a,b) for(re int i=(a),i##i=(b) ; i>=i##i ; --i)
#define gc getchar()
//#define gc (fs==ft&&(ft=(fs=buf)+fread(buf,1,1<<18,stdin),fs==ft))?0:*fs++
using namespace std;
const int N=4e5+10,inf=1e9+7;
char *fs,*ft,buf[1<<18];
LL read(){
    ll p=0; bool w=0; char ch=gc;
    while(!isdigit(ch)) w=ch=='-'?1:0,ch=gc;
    while(isdigit(ch)) p=p*10+ch-'0',ch=gc;
    return w?-p:p;
}
ll n,us1=3,us2=5,as1,as2;
map<ll,int>mp;
int main(){
	n=read();
	FOR(i,1,50){
		mp[us1]=i,us1*=3;
		if(us1>n) break;
	}
	FOR(i,1,50){
		if(mp[n-us2]){
			cout<<mp[n-us2]<<' '<<i;
			return 0;
		}
		us2=us2*5;
		if(us2>n) break;
	}
	cout<<-1;
	return 0;
}