// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define Graph vector<vector<ll>>
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1000000007;
// cout << fixed << setprecision(桁数);

int main(){
    ll N, M;
    cin >> N >> M;
    vector<ll> A(N), B(N), C(N, -3 * INF);
    Graph G(N);
    rep(i, N){
        cin >> A[i];
        B[i] = A[i];
    }
    rep(i, M){
        ll x, y;
        cin >> x >> y;
        x--;
        y--;
        G[x].push_back(y);
    }

    rep(i, N){
        sort(all(G[i]));
    }

    rep(i, N){
        for(ll j : G[i]){
            B[j] = min(B[j], B[i]);
            C[j] = max(A[j] - B[i], C[j]);
        }
    }

    ll ans = -3 * INF;  
    rep(i, N){
        ans = max(ans, C[i]);
        
    }

    cout << ans << endl;

}
/*
 * author: cyclexit
 * start from: 2021-01-16 12:06
 */
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  vector<pair<int, int>> edge(m);
  for (int i = 0; i < m; ++i) {
    cin >> edge[i].first >> edge[i].second;
    --edge[i].first;
    --edge[i].second;
  }
  sort(edge.begin(), edge.end());
  vector<int> mn(a), mx(a);
  int ans = -1e9 - 10;
  int u, v;
  for (int i = 0; i < m; ++i) {
    u = edge[i].first;
    v = edge[i].second;
    ans = max(ans, mx[v] - mn[u]);
    mx[u] = max(mx[u], mx[v]);
    mn[v] = min(mn[v], mn[u]);
  }
  cout << ans << '\n';
  return 0;
}