#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1;i < n+1; i++)
#define all(A) A.begin(),A.end()
typedef long long ll;

int main(){
  int n,m;
  cin >> n >> m;
  vector<ll> a(n+1);
  priority_queue<pair<ll,int>> p;
  rep1(i,n){
    cin >> a[i];
    p.push(make_pair(-a[i],i));
  }
  vector<vector<int>> to(n+1);
  rep(i,m){
    int x,y;
    cin >> x >> y;
    to[x].push_back(y);
  }
  vector<ll> dp(n+1,1e18);
  vector<bool> seen(n+1,0);
  while(p.size()>0){
    int start = p.top().second;
    p.pop();
    queue<int> q;
    q.push(start);
    while(q.size()>0){
      int now = q.front();
      q.pop();
      if(seen[now]) continue;
      seen[now] = 1;
      for(int next : to[now]){
        dp[next] = min(dp[next],dp[now]);
        dp[next] = min(dp[next],a[now]);
        q.push(next);
      }//next
    }//q
  }//p
  ll ans = -1e18;
  rep1(i,n){
    ans = max(ans,a[i]-dp[i]);
  }
  cout << ans << endl;
}

#include <bits/stdc++.h>
        
using namespace std;
        
int _____asdfwqerqwdcasdfasd = 0;
#define debug cout << "debug output " << "number: " << ++_____asdfwqerqwdcasdfasd << endl;
#define int long long
#define inf 2e18



int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); 
    cout.tie(0);

    int n, x;
    cin >> n >> x;
    vector<int> a(n);
    for (int& x : a) {
        cin >> x;
    }

    int ans = x;
    for (int k = 1; k <= n; k++) {
        vector<vector<int>> dp(k + 1, vector<int>(k, -1));
        dp[0][0] = 0;

        for (int x : a) {
            for (int c = k - 1; c >= 0; c--) {
                for (int r = 0; r < k; r++) {
                    if (dp[c][r] == -1) {
                        continue;
                    }
                    int nx = dp[c][r] + x;
                    dp[c + 1][nx % k] = max(dp[c + 1][nx % k], nx);
                }
            }
        }
        
        int st = dp[k][x % k];
        if (st == -1) {
            continue;
        }
        ans = min(ans, (x - st) / k);
    }

    cout << ans << "\n";
    return 0;
}
