#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const int N = 2e5 + 10;
int d[N], a[N];
ll f[N];
int n, m;

int h[N], e[N], ne[N], idx;
void add(int x, int y) {
	e[++idx] = y, ne[idx] = h[x], h[x] = idx;
}

int main()
{
	memset(h, -1, sizeof h);
	idx = 0;
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= n; ++i) scanf("%d", &a[i]);	
	for(int i = 1; i <= m; ++i) {
		int x, y;
		scanf("%d%d", &x, &y);
		add(x, y);
		++d[y];
	}
	
	queue<int> q;
	for(int i = 1; i <= n; ++i) if(!d[i]) q.push(i);
	memset(f, 0x3f, sizeof f);
	ll res = -1e18;
	while(!q.empty()) {
		auto u = q.front(); q.pop();
		res = max(res, 1ll * a[u] - f[u]);
		f[u] = min(f[u], 1ll * a[u]);
		for(int i = h[u]; ~i; i = ne[i]) {
			int v = e[i];
			f[v] = min(f[v], f[u]);
			--d[v];
			if(!d[v]) q.push(v);
		}
	}
	
	printf("%lld\n", res);
}
// abc188e.cpp 
#include <iostream>
#include <vector>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
const int INF = 1000000009;
int main()
{
    int n, m;
    cin >> n >> m;
    vector<int>a(n);
    rep(i, n) cin >> a[i];
    vector<vector<int>>w(n);
    int x, y;
    rep(i, m) {
        cin >> x >> y;
        x--; y--;
        w[y].push_back(x);
    }
    vector<int>dp(n,INF);
    int ans = -INF;
    for(int i=1;i<n;i++) { // dp[1]から計算する
        int now = INF;
        for (int j : w[i]) {
            now = min(now, dp[j]);
            now = min(now, a[j]); // 町jに来るまでで最安値を調べる
        }
        dp[i] = now; // 町iに来るまでで金の最安値（町iを含まない）
        //cout << "dp[" << i << "]=" << dp[i] << endl;
        if(now!=INF) ans = max(ans, a[i] - now);
        //cout << "ans=" << ans << endl;
    }
    cout << ans << endl;
}
/*
2 1
1000000000 1
1 2

3 1
1 1000000000 1
2 3

*/
