//you can do anything  //  be strong :| 
#include <bits/stdc++.h> 
#define ll long long
#define FAST ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define pk push_back
#define f first
#define s second 		
using namespace std;
int const maxn = 1e6+9 ;

ll pric[maxn] ;
bool vis[maxn] ;
vector<vector<ll>>adj;
ll dp[maxn] ;

void dfs(int cur )
{
	
	if(dp[cur]!=-1) return ;
	
	dp[cur] = pric[cur] ;
	vis[cur] =1 ;
	
	for(int i=0 ;i<adj[cur].size() ;i++)
	{
		if(!vis[ adj[cur][i] ])
			dfs(adj[cur][i]) ;
			
		dp[cur] = max( dp[adj[cur][i]] , dp[cur] ); 	
	}
}

void solve()
{	
		ll n ,m ;
		cin>>n>>m ;
		for(int i=0 ;i<n ;i++) cin>>pric[i];
		adj.resize(n);
		ll x ,y ;
		for(int i=0 ;i<m ;i++)
		{
			cin>>x>>y;
			x-- ; y-- ;
			adj[x].pk(y);
		}
		
		ll sum =INT_MIN ;
		memset(vis ,false ,sizeof(vis));
		memset(dp ,-1 ,sizeof(dp));
		for(int i=0 ;i<n ;i++)
		{
			if(!vis[i])
					dfs(i);
			for(auto j : adj[i])
			sum=max(sum ,  dp[j]- pric[i]);	
		}
		
		cout<<sum;
}

int main()
{
	ll t=1;
//	scanf("%lld" ,&t);
	while(t--) solve();
}


#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define loop(i,a,b) for(lli i=a;i<b;i++)
#define loopb(i,a,b) for (lli i=a;i>=b;i--)
#define pb push_back
#define mod 1000000007
#define fast() ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mem(a,b) memset(a,b,sizeof(a))
#define gcd(a,b) (__gcd((a),(b)))
#define lcm(a,b)(((a)*(b))/gcd((a),(b)))
#define ma 1e18
#define bc __builtin_popcountll
#define vi vector<lli>
#define pr pair<lli,lli>
#define vp vector<pr>
#define F  first
#define S   second
#define lld long double
#define PI  3.14159265358979
#define pri  priority_queue<lli>
#define prim  priority_queue<lli,vector<lli>,greater<lli>>
#define prip  priority_queue<pr>
#define primp  priority_queue<pr,vector<pr>,greater<pr>>
#define flush  cout<<flush
vector<lli>v[200001];
lli a[200001];
lli dis[200001];
lli vis[200001];


void dfs(lli x){
    vis[x] = 1;
    for(auto itr  : v[x]){
        if(!vis[itr]){
            dfs(itr);
        }
            dis[x] = max(dis[x] , max(dis[itr] , a[itr]));
           
        
    }
}


int main(){
    lli n,m,x,y;
    cin>>n>>m;
    loop(i,1,n+1){
        cin>>a[i];
        dis[i] = -1;
        vis[i] = 0;
        
    }
    
    
    
    loop(i,0,m){
        cin>>x>>y;
        v[x].pb(y);
    }
    
    loop(i,1,n+1){
        if(!vis[i]){
            dfs(i);
        }
    }
    
    
    lli ans = -1e16;
    loop(i,1,n+1){
        if(dis[i]!=-1){
            ans = max(ans ,  dis[i] - a[i]);
        }
        }
        cout<<ans<<"\n";
}