        #include<bits/stdc++.h>
#define loop(i, n) for(int i = 0; i < n; i++)
#define pb          push_back
#define ll          long long int
#define vi          vector<int>
#define pi          pair<int, int>
#define W(t)        int t; cin >> t; while(t--)
#define FIO         ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ff          first
#define ss          second
#define rep(i, a, b)for(ll i = a; i <= b; i++)
#define dep(i, a, b)for(ll i = a; i >= b; i--) 
#define all(x)      x.begin(), x.end()
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI                3.14159265
using namespace std;
const ll mod = (ll)(998244353);
ll test = 1;
vector<ll> read(int n){
    
    vector<ll> v(n);

    loop(i, n)
        cin >> v[i];
    return v;
}
std::vector<ll> a;
std::vector<ll> adj[200005];

bitset<200005> used;
std::vector<ll> dp(200005, -2e9);
void dfs(ll node){

    used[node]= 1;

    ll ans = INT_MIN;
    dp[node] = max(dp[node], a[node]);
    for(auto it : adj[node]){
        if(!used[it]){
            dfs(it);
        }
        dp[node] = max(dp[node], dp[it]);
    }
}
void solve(){
    ll i, j, k, m,n, cnt = 0, ans = 0, sum = 0;

    cin >> n >> m;

    a.resize(n);

    for(auto &i : a)cin >> i;

    rep(i, 0, m-1){
        ll u, v;
        cin >> u >> v;

        u--, v--;
        adj[u].pb(v);
    }
    ans = INT_MIN;
    rep(i, 0, n-1){
        
        if(!used[i])
            dfs(i);
    }

    ans = INT_MIN;
    rep(i, 0,n-1){
        for(auto j : adj[i]){
            ans = max(ans, dp[j]-a[i]);
        }
    }

    cout << ans << "\n";


    test++;
}

int main(){
    FIO
    
    #ifndef ONLINE_JUDGE
    freopen("C:/Codeforces/input.txt", "r", stdin);
    freopen("C:/Codeforces/output.txt", "w", stdout);
    #endif
    ll i = 1;
    //W(t)
    solve();
    
    return 0;
    
}
#include <bits/stdc++.h>
#define pb push_back
#define ll long long 
#define mp make_pair
#define si short int
#define speed ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define pill pair<ll,ll>
#define f first
#define s second
#define pilc pair<ll,char>
#define all(a) (a).begin(),(a).end()
#define rep(s,e,step) for(int i = (s); i < (e) ; i += step)
#define vrep(s,e,step) for(int j = (s); j < (e) ; j += step)
#define ex exit(0) 
#define sz(a) (a).size()
#define triple pair<pill, ll>
#define pinode pair<node*, node*>
#define quadra pair<pill, pill>
#define ld long double
using namespace std;
 
const ll N = 1E6 + 100;
//const ll M = 1e3 + 10;
const ll big = 1e9;
const ll pw = 491;
const ll hsh1 = 1000003651;
const long long mod = 1e9 + 7;
const long double EPS = 1e-14;
const ll block = 1e7;
const ll shift = 2e3;
mt19937_64 rofl(chrono::steady_clock::now().time_since_epoch().count());

ll n, m;
vector<ll> g[N];
ll a[N], b[N], ans = -big;
ll dp[N];

int main() {
	speed;
	cin >> n >> m;
	for(int i = 1; i <= n; i++) {
		cin >> a[i];
		b[i] = -big;
	}
	for(int i = 1, x ,y; i <= m; i++) {
		cin >> x >> y;
		g[y].pb(x);
	}
	for(int j = n; j >= 1; j--) {
		ans = max(b[j] - a[j], ans);
		b[j] = max(b[j], a[j]);
		for(auto u : g[j])
			b[u] = max(b[j], b[u]);	
	}
	cout << ans;
		
}
/*
10 3
0101110001


*/