#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
const int max_n = 50;
ll a[50],n,t;
void Solve(int l,int r,vector<ll>& v,ll tmp){
	if (l>r||tmp>t)return;
	if (l==r){
		v.push_back(a[l]+tmp);
		v.push_back(tmp);
		return;
	}
	Solve(l+1,r,v,tmp);Solve(l+1,r,v,tmp+a[l]);
}
int main(){
	ios::sync_with_stdio(0);
	cin>>n>>t;
	for (int i=1;i<=n;++i)cin>>a[i];
	int mid=n/2;
	vector<ll> lft,rgt;
	Solve(1,mid,lft,0);Solve(mid+1,n,rgt,0);
	lft.push_back(0);rgt.push_back(0);
	sort(lft.begin(),lft.end());
	sort(rgt.begin(),rgt.end());
	ll ans = 0;
	for (int i=0;i<lft.size();++i){
		ll l = lft[i];if (l>t)break;
		auto r = lower_bound(rgt.begin(),rgt.end(),t-l);
		ll rr=0;
		if (r!=rgt.end()){
			rr = *r;
			if (rr!=t-l){
				if (r==rgt.begin())rr=0;
				else rr = *(--r);
			}ans = max(ans,l+rr);
		}
		else ans = max(ans,l+rgt.back());
	}cout<<ans<<endl;
}
#include <bits/stdc++.h>

using namespace std;

const int N = 200000 + 10;

int n, m, a[N];
vector <int> G[N];
int in[N], dp[N];

int main() {
    memset(dp, -1, sizeof(dp));
    scanf("%d %d", &n, &m);
    for (int i = 1; i <= n; i++)    scanf("%d", a + i);
    for (int i = 1; i <= m; i++) {
        int u, v;   scanf("%d %d", &u, &v);
        G[u].push_back(v);
        in[v]++;
    }
    queue <int> Q;
    for (int i = 1; i <= n; i++) {
        if (!in[i]) {
            Q.push(i);
            dp[i] = a[i];
        }
    }
    int ans = INT_MIN;
    while (!Q.empty()) {
        int u = Q.front();  Q.pop();
        for (auto v : G[u]) {
            if (~dp[v]) dp[v] = min(dp[v], min(dp[u], a[u]));
            else    dp[v] = min(dp[u], a[u]);
            in[v]--;
            if (!in[v]) Q.push(v);
            ans = max(ans, a[v] - dp[v]);
        }
    }
    
    printf("%d\n", ans);
    return 0;
}