#include <bits/stdc++.h>
#define X first
#define Y second

using namespace std;
typedef long long llint;

const int maxn = 2e5+10;
const int base = 31337;
const int mod = 1e9+7;
const llint inf = (1LL << 60);
const int logo = 18;
const int off = 1 << logo;
const int treesiz = off << 1;

int n, m;
llint niz[maxn];
llint dp[maxn];
vector< int > graph[maxn];

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; i++) {
		scanf("%lld", niz+i);
	}
	for (int i = 0; i < m; i++) {
		int a, b;
		scanf("%d%d", &a, &b);
		
		graph[b].push_back(a);
	}
	
	llint sol = -2*inf;
	for (int i = 1; i <= n; i++) {
		dp[i] = inf;
		for (int j = 0; j < graph[i].size(); j++) {
			int tren = graph[i][j];
			dp[i] = min(dp[i], dp[tren]);
		}
		sol = max(sol, niz[i] - dp[i]);
		dp[i] = min(dp[i], niz[i]);
	}
	printf("%lld\n", sol);
	return 0;
}

#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };  // i<4:4way i<8:8way
int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int n,m;
    cin >> n >> m;
    vector<pair<ll,int>> a(n);
    vector<ll> b(n); // b[i] := 街iでのコスト
    vector<vector<int>> g(n);
    rep(i,n){
        cin >> a[i].first;
        a[i].second = i;
        b[i] = a[i].first;
    }
    rep(i,m){
        int x,y;
        cin >> x >> y;
        x--;y--;
        g[x].push_back(y);
    }
    sort(ALL(a));
    vector<bool> used(n);
    ll ans = -1e18;
    rep(i,n){
        ll cost = a[i].first;
        queue<int> q;
        q.push(a[i].second);
        while(!q.empty()){
            auto now = q.front();q.pop();
            for(auto next:g[now]){
                if(used[next])continue;
                else{
                    q.push(next);
                    used[next] = true;
                    chmax(ans,b[next] - cost);
                }
            }
        }
    }
    cout << ans << endl;
}   