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

int main(){
  ll n, m;
  cin >> n >> m;
  vector<pair<ll,ll>> As(n);
  vector<ll> A(n);
  vector<vector<ll>> g(n, vector<ll>(0));
  
  for(ll i=0; i<n; i++){
    ll a;
    cin >> a;
    As.at(i).first = a;
    As.at(i).second = i;
    A.at(i) = a;
  }
  for(ll i=0; i<m; i++){
    ll x, y;
    cin >> x >> y;
    g.at(x-1).push_back(y-1);
  }
  
  sort(As.begin(), As.end());
  
  
  vector<ll> P(n, 0);
  ll ans = -10000000000;
  queue<ll> que;
  for(int i=0;i<n;i++){
    ll now = As.at(i).second;
    que.push(now);
    while (!que.empty()) {
      ll v = que.front();
      que.pop();
      if(now!=v) {
        ans = max(ans, A.at(v) - A.at(now));
        P.at(v) = 1;
      }
      for (ll nv : g.at(v)) {
        if (P.at(nv) == 1) continue;
        que.push(nv);
      }
    }
  }
  cout << ans << endl;
  return 0;
}
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef long double LD;
typedef pair<LL,LL> pii;
typedef pair<LL,pii> ppi;
typedef pair<pii,pii> ppp;
#define FOR(i, n) for(int i = 1; i<=n; i++)
#define F0R(i, n) for(int i = 0; i<n; i++)
#define mp make_pair
#define pb push_back
#define f first
#define s second

template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p) { return cout << "(" << p.f << ", " << p.s << ")"; }
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v) {cout << "["; F0R(i, v.size()) {if (i) cout << ", "; cout << v[i];} return cout << "]";}

//var 
const LL INF = 1e17;
LL t, n, m, a[200005], ans = -INF;
vector<LL> e[200005], e2[200005];
LL v[200005], minbuy[200005], maxsell[200005], v2[200005];

void dfs(LL g){
	if(v[g]) return;
	v[g] = 1;

	for(auto u : e[g]){
		if(!v[u]) dfs(u);
		maxsell[g] = max(maxsell[g], maxsell[u]);
		ans = max(ans, maxsell[u] - minbuy[g]);
	} 

	//cout << g << '\n';
}

void dfs2(LL g){
	if(v2[g]) return;
	v2[g] = 1;
	for(auto u : e2[g]){
		if(!v2[u]) dfs2(u);
		minbuy[g] = min(minbuy[g], minbuy[u]);
	}
}

void solve(){
	cin >> n >> m;
	FOR(i, n)
		cin >> a[i];

	LL t1, t2;
	FOR(i, m){
		cin >> t1 >> t2;
		e[t1].pb(t2);
		e2[t2].pb(t1);
	}

	FOR(i, n){
		maxsell[i] = a[i];
		minbuy[i] = a[i];
	}

	for(int i = n; i>=1; i--){
		if(v2[i]) continue;
		dfs2(i);
	}

	FOR(i, n){
		if(v[i]) continue;
		dfs(i);
	}
	
	cout << ans << '\n';
}

int main(){
	ios_base::sync_with_stdio(0); 
	cin.tie(0);

	t = 1;
	//cin >> t;
	FOR(i, t)
		solve();

	cout.flush();
	return 0;
}