#include <bits/stdc++.h>
 
typedef long long int ll;
typedef long double ld;
typedef unsigned long long int ull;
typedef long int li;
 
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 
#define test ll t; cin >> t; while(t--)
const long long int cons = 200005;
const long long int MOD = 1000000007;
// const long long int MOD = 998244353; 
const long long int const_INT_MAX = 1000000000000000000;
const long long int const_INT_MIN = -1 * 1000000000000000000;
 
using namespace std;
// to sort pair vector in reverse order 
bool sortinrev(const pair<ll,ll> &a, const pair<ll,ll> &b){ 
    return (a.first > b.first); 
}
// to sort pair vector according to the second elements 
bool sortbysec(const pair<ll,ll> &a, const pair<ll,ll> &b){ 
    return (a.second < b.second); 
}
// to sort pair vector according to the second elements in reverse order
bool sortbysecinrev(const pair<ll,ll> &a, const pair<ll,ll> &b){ 
    return (a.second > b.second); 
}
ll lcm(ll x, ll y){
    return (ll)((x * y) / __gcd(x, y)); 
}
ll mod_expo(ll x, ll y, ll p){  
    // reference from GFG
    ll res = 1;
    if((x + p) % p == 0){
        res = 0;
    }
    else {
        x = (x + p) % p;
        while (y > 0){   
            if (y & 1){ 
                res = (res*x + p) % p; 
            }
            y = y>>1;
            x = (x*x + p) % p;  
        }  
    }
    return res;     
}
void usaco(string str = ""){   
    fastio;
    if(str.size()){
        freopen((str + ".in").c_str(), "r", stdin);
        freopen((str + ".out").c_str(), "w", stdout);
    }
}
vector<ll> adj[cons];
ll dp[cons]; 
int main(){
    usaco();
    ll n, m; cin >> n >> m;
    ll a[n]; 
    for(ll i=0;i<n;i++){
        cin >> a[i]; 
    }
    for(ll i=0;i<m;i++){
        ll u, v; cin >> u >> v;
        u--; v--; 
        adj[u].push_back(v); 
    }
    for(ll i=0;i<n;i++){
        dp[i] = const_INT_MIN;
    }
    for(ll i=n-1;i>=0;i--){
        for(auto u : adj[i]){
            dp[i] = max(dp[i], max(dp[u], a[u])); 
        }
    }
    ll fin_ans = const_INT_MIN;
    for(ll i=0;i<n;i++){
        fin_ans = max(fin_ans, dp[i] - a[i]); 
    }
    cout << fin_ans << "\n";
}
#include<bits/stdc++.h>
#define int long long
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pi;
const int mod = 1e9 + 7;
const int nax = 1e6;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int a[nax], dp[nax], deg[nax], mn[nax];
vector<int> E[nax];

int32_t main() {
 
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    for(int i = 1; i <= n; i++) {
        mn[i] = 2e18;
        dp[i] = -2e18;
    }
    for(int i = 1; i <= n; i++) cin >> a[i];
        
    for(int i = 1; i <= m; i++) {
        int x, y;
        cin >> x >> y;
        E[x].pb(y);
        deg[y]++;
    }

    queue<int> Q;
    vector<int> ord;
    for(int i = 1; i <= n; i++) {
        if(!deg[i]) {
            Q.push(i);
        }
    }

    while(Q.size()) {
        int node = Q.front();
        Q.pop();
        ord.pb(node);
        for(auto it : E[node]) {
            deg[it]--;
            if(!deg[it]) {
                Q.push(it);
            }
        }
    }

    int ans = -2e18;

    for(auto x : ord) {
        mn[x] = min(mn[x], a[x]);
        for(auto it : E[x]) {
            ans = max(ans, a[it] - mn[x]);
            mn[it] = min(mn[it], mn[x]);
        }
    }
    cout << ans << '\n';
    
    
    return 0;
}
 


// 9