#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include <unordered_map>
//#include"testlib.h"
#define endl '\n'
#define all(v) v.begin(),v.end()
#define allr(s) s.rbegin(),s.rend()
#define RT(s) return cout<<s,0
#define sz(s)    (int)(s.size())
//#define PI acos(-1)
#define EPS 1e-8
#define watch(x) cout << (#x)<<" = "<<x<<endl
#define mk(x, y) make_pair(x, y)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
int dy[] = { 1, -1, 0, 0, -1, 1, 1, -1 };
int dx[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
void file() {
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
#else
	//freopen("gcd.in", "r", stdin);
	//freopen("out.txt", "w", stdout);
#endif
}

void fast() {
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
}
const int N = 2e5 + 9;
vi adjL[N];
ll mem[N][10], cost[N];
int n;
ll solve(int u, int type) {
	if (!sz(adjL[u]) && !type) return -1e10;
	ll& ret = mem[u][type];
	if (ret != -1) return ret;
	ret = -1e10;
	if (!type) {
		for (auto& it : adjL[u]) {
			ret = max(ret, solve(it, 1) - cost[u]);
			ret = max(ret, solve(it, 0));
		}
	}
	else {
		ret = cost[u];
		for (auto& it : adjL[u])
			ret = max(ret, solve(it, 1));
	}
	return ret;
}
int main() {
	file();
	fast();
	memset(mem, -1, sizeof mem);
	int m; cin >> n >> m;
	for (int i = 1; i <= n; i++)
		cin >> cost[i];
	while (m--) {
		int x, y; cin >> x >> y;
		adjL[x].push_back(y);
	}
	ll ans = LLONG_MIN;
	for (int i = 1; i <= n; i++)
		ans = max(ans, solve(i, 0));
	cout << ans << endl;
	return 0;
}
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cerr<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;

vi to[MX];
vi a;
vi dp(MX,-1);

int dfs(int u){
    if(dp[u]>-1) return max(a[u], dp[u]);
    int res = -1;
    for(int v: to[u]){
        res = max(res,dfs(v));
    }
    dp[u] = res;
    return max(a[u],res);
}

int main() {
    int n,m; cin >> n >> m;
    rep(i,n){
        int ai; cin >> ai;
        a.push_back(ai);
    }
    rep(i,m){
        int x,y; cin >> x >> y;
        --x,--y;
        to[x].push_back(y);
    }
    rep(i,n) dfs(i);
    int ans = -INF;
    rep(i,n){
        int tos = to[i].size();
        if(tos == 0) continue;
        if(dp[i] == -1) continue;
        // printf("size: %d\n",(int)to[i].size());
        // printf("ans: %d\n",dp[i]-a[i]);
        ans = max(dp[i]-a[i],ans);
    }
    // cout << endl;
    cout << ans << endl;
    /*
    rep(i,n){
      cout << dp[i] << endl;
    }
    */
    return 0;
}
