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

template <class A, class B> bool cmin(A& a, B b) { return a > b && (a = b, true); }
template <class A, class B> bool cmax(A& a, B b) { return a < b && (a = b, true); }

signed main() {
  cin.tie(nullptr)->sync_with_stdio(false);

  int N, M;
  cin >> N >> M;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  vector<vector<int>> G(N);
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b, a--, b--;
    G.at(a).push_back(b);
  }

  vector<int> DP(N, INT_MIN);
  auto dfs = [&](auto&& dfs, int now, int pre, int mi) -> void {
    cmin(mi, A.at(now));
    for (const auto& next : G.at(now)) {
      if (next == pre) continue;
      if (cmax(DP.at(next), A.at(next) - mi)) dfs(dfs, next, now, mi);
    }
  };
  for (int i = 0; i < N; i++) {
    dfs(dfs, i, -1, INT_MAX);
  }
  cout << *max_element(DP.begin(), DP.end()) << '\n';
}
//BISMILAHIRAHMANIR RAHIM
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define int               long long
#define pb                push_back
#define ppb               pop_back
#define pf                push_front
#define ppf               pop_front
#define all(x)            (x).begin(),(x).end()
#define allr(x)			  (x).rbegin(),(x).rend()
#define uniq(v)           (v).erase(unique(all(v)),(v).end())
#define sz(x)             (int)((x).size())
#define fr                first
#define sc                second
#define pii               pair<int,int>
#define loop(i,a,b)        for(int i=a;i<b;i++)
#define mem1(a)           memset(a,-1,sizeof(a))
#define mem0(a)           memset(a,0,sizeof(a))
#define ppc               __builtin_popcount
#define ppcll             __builtin_popcountll
#define br                break
#define con               continue 

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
template<typename T1,typename T2>istream& operator>>(istream& in,pair<T1,T2> &a){in>>a.fr>>a.sc;return in;}
template<typename T1,typename T2>ostream& operator<<(ostream& out,pair<T1,T2> a){out<<a.fr<<" "<<a.sc;return out;}
template<typename T,typename T1>T amax(T &a,T1 b){if(b>a)a=b;return a;}
template<typename T,typename T1>T amin(T &a,T1 b){if(b<a)a=b;return a;}
 
const long long INF=1e18;
const int32_t M=1e9+7;
const int32_t MM=998244353;

priority_queue<pii, vector<pii>, greater<pii> >q;
const int mxx = 2e5+5;
vector<vector<int>>adj(mxx);
vector<int>up(mxx,-1e18);
vector<int>v(mxx);
map<int,int>vis;
void dfs(int j){
	vis[j]=1;

	up[j]=max(up[j],v[j]);

	for(int i:adj[j]){
		if(vis[i]==0)dfs(i);
		up[j]=max(up[i],up[j]);
	}
}
void solv(){
	int n,m,x,y;
	cin>>n>>m;
	loop(i,1,n+1)cin>>v[i];

	loop(i,0,m){
		cin>>x>>y;
		adj[x].pb(y);
	}

	loop(i,1,n+1){
		if(vis[i]==0)dfs(i);
	}
	int mx = -1e18;

	loop(i,1,n+1){
		for(int j:adj[i])mx = max(mx,up[j]-v[i]);
	}
	cout<<mx<<endl;
}
signed main(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
    ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);

	solv();







}
///ALHAMDULILLAH//