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

int main() {
	cin.tie(0)->sync_with_stdio(0);
	int n, m;
	cin >> n >> m;
	vector<pair<int, int>> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i].first;
		a[i].second = i;
	}
	sort(begin(a), end(a));
	map<int, int> mp;
	for (const auto& [v, i] : a) {
		mp[i] = v;
	}
	vector<vector<int>> g(n);
	while (m--) {
		int x, y;
		cin >> x >> y;
		--x, --y;
		g[x].push_back(y);
	}
	int ans = -(1 << 30);
	vector<bool> seen(n, false);
	for (const auto& [v, i] : a) {
		queue<int> q;
		q.push(i);
		while (!q.empty()) {
			int p = q.front();
			q.pop();
			for (const auto& ni : g[p]) {
				if (seen[ni]) continue;
				ans = max(ans, mp[ni] - v);
				q.push(ni);
				seen[ni] = true;
			}
		}
	}
	cout << ans << '\n';
}

#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long li;
#define rep(i,n) for(int i=0;i<(n);i++)
#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }

// Container コンテナ型, map以外
template< template<class ...> class Ctn,class T>
std::ostream& operator<<(std::ostream& os,const Ctn<T>& v){
  auto itr=v.begin();
  while(itr!=v.end()){
    if(itr!=v.begin())cout << " ";
    cout << *(itr++);
  }
  return os;
};

int main(){
  int n,m; cin >>n >>m;
  vector<li> a(n);
  rep(i,n) cin >>a[i];
  vector<vector<int>> adj(n);
  rep(i,m) {
    int x,y; cin >>x >>y; x-- ; y--;
    adj[x].push_back(y);
  }
  li s=0; for(li x:a) s=max(s,x);
  if(df)print("s",s);
  vector<li> dp(n,s*2);
  rep(i,n){
    for(int x:adj[i]){
      dp[x]=min({dp[x],a[i],dp[i]});
    }
  }
  if(df)print(dp);
  li   ans=-s;
  rep(x,n){
    ans=max(ans,a[x]-dp[x]);
  }
  print(ans);
}
