#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <deque>
#include <set>
#include <limits>
#include <string>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <numeric>

using namespace std;

using ll = long long;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)

/* input & output */
#define IN(a) cin >> a
#define OUT(a) cout << a << endl
#define OUT_PREC(a, n) cout << fixed << setprecision(n) << a << endl

/* vector */
#define VEC(t, v, n, ini) vector<t> v(n, ini)
#define VEC2(t, v, m, n, ini) vector<vector<t>> v(m, vector<t>(n, ini))
#define VEC3(t, v, k, m, n, ini) vector<vector<vector<t>>> v(k, vector<vector<t>>(m, vector<t>(n, ini)))

/* bit */
#define IS_TRUE(bit, i) (bit & (1 << i))   // bitのi成分
#define FLAG_ON(bit, i) (bit｜(1 << i))    // bitのi成分をtrueに
#define FLAG_OFF(bit, i) (bit & ~(1 << i)) // bitのi成分をfalseに
#define ALL_TRUE(n) (1 << n)               // 2^n
#define CMPSET(bit, s) (bit ^ s)           // sのbitに対する補集合
#define INCLUDES(a, b) ((a & b) == b)      // aはbを含むか

#define INF 1e12

ll solve()
{
    int n, m;
    cin >> n >> m;
    vector<ll> a(n), dp(n, INF);
    FOR(i, 0, n)
    {
        IN(a[i]);
    }

    vector<vector<int>> t(n, vector<int>{});

    FOR(i, 0, m)
    {
        int x, y;
        cin >> x >> y;
        --x;
        --y;
        t[y].emplace_back(x);
    }

    FOR(i, 0, n)
    {
        for (int j : t[i])
        {
            dp[i] = min(min(dp[i], dp[j]), a[j]);
        }
    }

    ll ans = -INF;

    FOR(i, 0, n)
    {
        if (a[i] - dp[i] > ans)
            ans = a[i] - dp[i];
    }

    return ans;
}

int main()
{
    /* solve */
    OUT(solve());
    system("pause");
}
#include <algorithm>
#include <array>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <utility>
#include <vector>
#include <stack>
using namespace std;
using ll = long long int;
// fast IO
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
////////// 	Template structure for debugging
#define tr(...) trace(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void trace(const char* name, Arg1&& arg1){
  cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void trace(const char* names, Arg1&& arg1, Args&&... args){
  const char *comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " | ";
  trace(comma + 1, args...);
}
#define print(...) pr(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void pr(const char* name, Arg1&& arg1){
  cout << arg1 << endl;
}
template <typename Arg1, typename... Args>
void pr(const char* names, Arg1&& arg1, Args&&... args){
  const char *comma = strchr(names + 1, ',');
  cout << arg1 << " ";
  pr(comma + 1, args...);
}
void printV(vector<int> &arr)
{
	cout << "Vector : ";
	for(int i=0;i<arr.size();i++)
		cout << arr[i] << " \n"[ i == arr.size()-1 ];
}
void printV(vector<long long> &arr)
{
	cout << "Vector : ";
	for(int i=0;i<arr.size();i++)
		cout << arr[i] << " \n"[ i == arr.size()-1 ];
}
void printA(int arr[], int n) {
  cout << "Array : ";
  for (int i = 0; i < n; i++)
	cout << arr[i] << " \n"[i == n - 1];
}

/////////////////////////////////////////////////////////////////////////////
////////////////////// DO NOT TOUCH BEFORE THIS LINE ////////////////////////
/////////////////////////////////////////////////////////////////////////////
const ll INF = 1e15;
ll N, M, ans = -INF;
vector<ll> C, vis;
vector<vector<ll>> G;

ll dfs(ll curr, ll mn){
	vis[curr] = -INF;
	for(auto child: G[curr]){
		if(vis[child] == 0){
			vis[curr] = max(vis[curr], dfs(child, min(C[child], mn)));
		}
		else vis[curr] = max(vis[curr], vis[child]);
	}

	if(!G[curr].empty())ans = max(ans, vis[curr] - mn);
	//tr(curr, vis[curr], mn);
	vis[curr] = max(vis[curr], C[curr]);
	return vis[curr];
}
void solve(int tc = 1){
	cin >> N >> M;
	C.resize(N);
	vis.resize(N, 0);
	G.resize(N);
	for(auto &a: C)cin >> a;
	for(int i=0; i<M; i++){
		int a, b;
		cin >> a >> b;
		a--, b--;
		G[a].push_back(b);
	}
	for(int i=0; i<N; i++){
		if(vis[i])continue;
		dfs(i, C[i]);
	}
	cout << ans << endl;
}

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