#include <bits/stdc++.h>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }


#define MAX_V 200005 

ll A[MAX_V], X[MAX_V], Y[MAX_V];
ll buy[MAX_V];
ll ans = -3e9;
int V;
#define SZ(x) ((int)((x).size()))
vector<int> G[MAX_V];
bool used[MAX_V];
void add_edge(int from, int to){
    G[from].push_back(to);
}


int main() {
    ll N, M;
    cin >> N >> M;
    V = N;
    rep(i, N)cin >> A[i];
    rep(i, M){
        cin >> X[i] >> Y[i];
        X[i]--;
        Y[i]--;
        add_edge(X[i], Y[i]);
    }
    rep(i, MAX_V)buy[i] = 3e9;
    
    //mmax[0] = A[0];
    rep(v, N){
        //cout << v << " " << buy[v] << " " << A[v] << endl;
        
        chmax(ans, A[v] - buy[v]);
        rep(i, SZ(G[v])){
            ll j = G[v][i];
            chmin(buy[j], buy[v]);
            chmin(buy[j], A[v]);
        }
    }
    cout << ans;
}
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define N 2114514
const ll mod = 998244353;
const ll inf = 1000000000000000000;

P a[N];
ll num[N];
bool used[N];
int main() {
    ll n, m;
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
        ll x;
        cin >> x;
        num[i] = x;
        a[i] = {x, i};
    }
    vector<vector<ll>> v(n + 1);
    for (int i = 0; i < m; i++) {
        ll x, y;
        cin >> x >> y;
        v[x].push_back(y);
    }
    sort(a + 1, a + n + 1);
    queue<ll> que;
    ll ans = -inf;
    for (int i = 1; i <= n; i++) {
        que.push(a[i].second);
        ll ma = -inf;
        while (!que.empty()) {
            ll p = que.front();
            que.pop();
            for (ll x : v[p]) {
                if (used[x]) continue;
                used[x] = 1;
                ma = max(ma, num[x] - a[i].first);
                que.push(x);
            }
        }
        ans = max(ans, ma);
    }
    cout << ans << endl;
    return 0;
}
