#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define mod 1000000007ll
//#define mod 998244353ll
#define endl '\n'
#define inf ((ll)1e18+1)
#include<chrono>
using namespace chrono;
mt19937_64 rng(high_resolution_clock::now().time_since_epoch().count());
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update>
#define debr(x,y) {cout<<"-->  "<<#x<<" to "<<#y<<" :  "; auto itr=x; while(itr!=y) cout<<(*itr++)<<' '; cout<<endl; }
#define deba(x) {cout<<"-->  "<<#x<<" :  "; for(auto ele:(x)) cout<<ele<<"  "; cout<<endl; }
#define deb(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s);istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {cout<<endl;}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a <<"  ,  ";
    err(++it, args...);
}
ll cl(ll a,ll b){
	return a/b+(a%b!=0);
}

const int maxN=2e5+5;
vector<int> adj[maxN];
int n,m;
int price[maxN],deg[maxN];
ll cost[maxN];
ll ans=-inf;


int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	ll t=1;
	// cin>>t;
	while(t--){
		cin>>n>>m;
		for(int x=1;x<=n;x++){
			cin>>price[x];
			cost[x]=inf;
		}
		for(int x=1;x<=m;x++){
			int xi,yi;
			cin>>xi>>yi;
			adj[xi].push_back(yi);
			deg[yi]++;
		}
		priority_queue<array<ll,2>,vector<array<ll,2>>,greater<array<ll,2>>> pq;
		for(int x=1;x<=n;x++){
			if(deg[x]==0){
				pq.push({price[x],x});
				cost[x]=price[x];
			}
		}
		while(!pq.empty()){
			auto pa=pq.top();
			pq.pop();
			ll mini=pa[0],u=pa[1];
			for(int v:adj[u]){
				if(cost[v]>mini){
					cost[v]=mini;
					pq.push({min(mini,(ll)price[v]),v});
				}
			}
		}
		for(int x=1;x<=n;x++){
			if(deg[x]>0){
				ans=max(ans,price[x]-cost[x]);
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

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

int inf = 1001001001;

int main(){
  int N,M;
  cin >> N >> M;
  vector<int> A(N);
  for(int i=0;i<N;i++) cin >> A[i];
  vector<vector<int>> G(N,vector<int>(0));
  for(int i=0;i<M;i++){
    int x,y;
    cin >> x >> y;
    x--;y--;
    G[x].push_back(y);
  }
  
  vector<int> V1(N),V2(N,inf);
  for(int i=0;i<N;i++) V1[i] = A[i];
  for(int i=0;i<N;i++){
    for(int j=0;j<G[i].size();j++){
      int v = G[i][j];
      V1[v] = min(V1[v],V1[i]);
      V2[v] = min(V2[v],V1[i]);
    }
  }
  
  int ans = -inf;
  for(int i=0;i<N;i++) if(V2[i]!=inf) ans = max(ans,A[i]-V2[i]);
  cout << ans << endl;
  return 0;
}
