#include<bits/stdc++.h>
using namespace std;
#define debug(x) cerr<<#x<<" = "<<x
#define sp <<"  "
#define el <<endl
#define fgx cerr<<" ------------------------------------------------ "<<endl
#define LL long long
#define DB double
#define mpt make_pair
#define pb push_back
inline LL read(){
	LL nm=0; bool fh=true; char cw=getchar();
	for(;!isdigit(cw);cw=getchar()) fh^=(cw=='-');
	for(;isdigit(cw);cw=getchar()) nm=nm*10+(cw-'0');
	return fh?nm:-nm;
}
#define M 200200
#define INF 2000000000
int n,m,mx[M],a[M],fs[M],to[M],nt[M],tot,ind[M],oud[M],H[M],ans=-INF; bool vis[M];
inline void link(int x,int y){to[++tot]=y,nt[tot]=fs[x],fs[x]=tot;}
inline void dfs(int x){
	if(vis[x]) return; vis[x]=true,mx[x]=a[x];
	for(int i=fs[x];i;i=nt[i])
		dfs(to[i]),mx[x]=max(mx[x],mx[to[i]]),H[x]=max(H[x],mx[to[i]]);
}

int main(){
	n=read(),m=read();
	for(int i=1;i<=n;i++) a[i]=read();
	for(int i=1,x,y;i<=m;i++) x=read(),y=read(),link(x,y),++oud[x],++ind[y];
	for(int i=1;i<=n;i++) if(!ind[i]) dfs(i);
	for(int i=1;i<=n;i++) if(oud[i]) ans=max(ans,H[i]-a[i]);
	printf("%d\n",ans);return 0;
}

#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
#define forn(i,a,b)for(int i=(a),_b=(b);i<=_b;i++)
#define fore(i,b,a)for(int i=(b),_a=(a);i>=_a;i--)
#define rep(i,n)for(int i=0,_n=n;i<n;i++)
#define ll long long
#define pii pair<int,int>
#define vi vector<int>
#define vpii vector<pii>
#define m_p make_pair
#define re return
#define pb push_back
#define si set<int>
#define ld long double
#define X first
#define Y second
#define st string
#define ull unsigned long long
#define mod 1000000007
#define INF 1000000007
#define x1 XZVJDFADSPFOE
#define y1 GASDIJSLDAEJF
#define x2 DFDAJKVOHKWIW
#define y2 PSFSAODSXVNMQ
#define LLINF 0x3f3f3f3f3f3f3f3fLL
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
using namespace std;
inline void read(int &x)
{
	short negative=1;
    x=0;
    char c=getchar();
    while(c<'0' || c>'9')
    {
		if(c=='-')
			negative=-1;
		c=getchar();
	}
    while(c>='0' && c<='9')
        x=(x<<3)+(x<<1)+(c^48),c=getchar();
    x*=negative;
}
ll quickpower(ll n,ll k){
	ll ans=1;
	while(k){
		if(k%2){
			ans*=n;
			ans%=mod;
		}
		n*=n;
		n%=mod;
		k/=2;
	}
	return ans;
}
string int_to_string(int n)
{
	string s="";
	while(n)
	{
		int now=n%10;
		s+=now+'0';
		n/=10;
	}
	reverse(s.begin(),s.end());
	return s;
}
int string_to_int(string s)
{
	int n=0;
	rep(i,s.size())
	{
		n*=10;
		n+=s[i]-'0';
	}
	return n;
}
int n,m;
vector<int>v[200100];
ll a[200100];
bool used[200100];
ll can[200100];
void dfs(int u)
{
	used[u]=1;
	rep(i,v[u].size())
	{
		if(!used[v[u][i]])dfs(v[u][i]);
		can[u]=max(can[u],can[v[u][i]]);
		can[u]=max(can[u],a[v[u][i]]);
	}
}
int main()
{
	ios::sync_with_stdio(0);
	cin>>n>>m;
	rep(i,n)cin>>a[i];
	rep(i,m)
	{
		int x,y;
		cin>>x>>y;
		x--;
		y--;
		v[x].pb(y);
	}
	rep(i,n)can[i]=-1e18;
	rep(i,n)
	{
		if(!used[i])dfs(i);
	}
	ll ans=-1e18;
	rep(i,n)
	{
		ans=max(ans,can[i]-a[i]);
	}
	cout<<ans<<endl;
	return 0;
}
