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

int main(void) {
  int N, M;
  cin >> N >> M;
  vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  vector<vector<int>> graph(N);
  for (int i = 0; i < M; i++) {
    int X, Y;
    cin >> X >> Y;
    X--;
    Y--;
    graph[X].push_back(Y);
  }

  vector<long long> minimum(N, 1e10);
  minimum[0] = A[0];
  for (int i = 0; i < N; i++) {
    for (auto g : graph[i]) {
      minimum[g] = min({minimum[g], minimum[i], A[i]});
    }
  }

  long long ans = -1e10;
  for (int i = 1; i < N; i++) {
    ans = max(A[i] - minimum[i], ans);
  }

  cout << ans << endl;
  return 0;
}
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
#define FAST  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define int long long 
#define ll int
#define all(a) a.begin(),a.end()	
#define rev(a) a.rbegin(),a.rend()	
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; //less_equal for multiset
#define ar array
#define pb push_back
#define fi(a,b) for(int i=a;i<(b);i++)
#define fj(a,b) for(int j=a;j<(b);j++)
#define fk(a,b) for(int k=a;k<(b);k++)
const double pi=acosl(-1);

vector<vector<int>> adj;
vector<int> a;
int n,m;
vector<ar<int,3>> dp;
vector<bool> vis;

// 0-->dp value (profit)
// 1-->max number till here
// 2-->min number till here
vector<int> maxi,mini;

void dfs(int node)
{
	maxi[node]=max(maxi[node],a[node]);
	mini[node]=min(mini[node],a[node]);
	vis[node]=true;
	for(auto i:adj[node])
	{
		mini[i]=min(mini[i],mini[node]);
		if(!vis[i])
		{
			dfs(i);
		}
		maxi[node]=max(maxi[i],maxi[node]);
	}
}

void solve()
{
	cin>>n>>m;
	a=vector<int> (n);
	fi(0,n) cin>>a[i];
	adj=vector<vector<int>> (n);
	// dp=vector<ar<int,3>> (n);
	const int INF=1e13;
	maxi=vector<int> (n);
	mini=vector<int> (n,INF);
	vis=vector<bool> (n);
	fi(0,m)
	{
		int x,y;
		cin>>x>>y;
		--x,--y;
		adj[x].pb(y);
	}
	fi(0,n)
	{
		if(!vis[i])
		{
			dfs(i);
		}
	}
	int ans=-INF;
	fi(0,n)
	{
		for(auto x:adj[i])
		{
			ans=max(ans,maxi[x]-mini[i]);
		}
	}
	cout<<ans<<'\n';
}

signed main()
{
	FAST;
	int tt=1;
	// cin>>tt;	
	while(tt--)
	{
		solve();
	}	
}



