#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <cmath>
#include <string>
#include <vector>
#include <stack>
#include <map>
#include <sstream>
#include <cstring>
#include <set>
#include <cctype>
#include <list>
#include <bitset>
#define IO                       \
    ios::sync_with_stdio(false); \
    // cin.tie(0);                  \
    // cout.tie(0);
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int maxn = 2e5 + 100;
const int maxm = 1e6 + 10;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const LL mod = 1e9 + 7;
// int dis[8][2] = {0, 1, 1, 0, 0, -1, -1, 0, 1, -1, 1, 1, -1, 1, -1, -1};
struct Edge
{
    int next, to;
} e[maxn << 2];
int head[maxn];
LL a[maxn];
LL dp[maxn];
LL ans = -2 * mod;
int in[maxn];
int n, m;
int k = 0;

void add(int u, int v)
{
    e[k].next = head[u];
    e[k].to = v;
    head[u] = k++;
}
void topo()
{
    queue<int> q;
    for (int i = 1; i <= n; i++)
        if (in[i] == 0)
        {
            q.push(i);
        }
    while (!q.empty())
    {
        int u = q.front();
        q.pop();
        if (a[u] - dp[u] > ans)
            ans = a[u] - dp[u];
        // dp[u] = min(dp[u], a[u]);
        for (int i = head[u]; ~i; i = e[i].next)
        {
            int v = e[i].to;
            dp[v] = min(dp[v], min(dp[u], a[u]));
            in[v]--;
            if (in[v] == 0)
                q.push(v);
        }
    }
    return;
}
int main()
{
#ifdef ONLINE_JUDGE
#else
    freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
#endif
    IO;
    int x, y;
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
        head[i] = -1;
        dp[i] = 1e10;
    }
    for (int i = 0; i < m; i++)
    {
        cin >> x >> y;
        add(x, y);
        in[y]++;
    }
    topo();
    cout << ans;
    return 0;
}

//Bismillahirrahmanirrahim

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

typedef long long lo;
typedef pair< lo,lo > PII;

#define fi first
#define int long long
#define se second
#define mp make_pair
#define endl "\n"
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)

const lo inf = 1000000000000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 500005;
const lo mod = 1000000007;

int n,m,b[li],a[li],k,flag,t,dp[li],vis[li];
int cev;
string s;
vector<int> v[li];

inline void dfs(int node){
	if(vis[node])return ;
	vis[node]=1;
	for(auto go:v[node]){
		dfs(go);
		dp[node]=max(dp[node],max(a[go],dp[go]));
	}
	cev=max(cev,dp[node]-a[node]);
}

int32_t main(void){
	scanf("%lld %lld",&n,&m);
	FOR scanf("%lld",&a[i]);
	FOR dp[i]=-inf;
	for(int i=1;i<=m;i++){
		int x,y;
		scanf("%lld %lld",&x,&y);
		v[x].pb(y);
		//~ v[y].pb(x);
	}
	cev=-inf;
	FOR{
		if(vis[i])continue;
		dfs(i);
	}
	printf("%lld\n",cev);
	return 0;
}

