#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <functional>
#include <stdio.h>
#include <ctype.h>
#include <random>
#include <string.h>
#include <unordered_map>
#include <cstdio>
#include <climits>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long ll;

ll gcd(ll x, ll y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}
ll kai(ll x, ll y, ll m) {
	ll res = 1;
	for (ll i = x - y + 1; i <= x; i++) {
		res *= i; res %= m;
	}
	return res;
}
ll mod_pow(ll x, ll y, ll m) {
	ll res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

ll comb(ll x, ll y, ll m) {
	if (y > x)return 0;
	return kai(x, y, m) * mod_pow(kai(y, y, m), m - 2, m) % m;
}

const ll INF = 1000000000000000000;

int n, m, a[200010], x[200010], y[200010];
vector<int> vec[200010];
ll d[200010];
ll ans = -INF;

signed main() {
	std::random_device rnd;
	std::mt19937_64 mt(rnd());
	cin >> n >> m;
	for (int i = 1; i <= n; i++)cin >> a[i];
	fill(d, d + n + 1, INF);
	for (int i = 0; i < m; i++) {
		cin >> x[i] >> y[i];
		vec[y[i]].push_back(x[i]);
	}
	d[1] = a[1];
	for (int i = 2; i <= n; i++) {
		ll mi = INF;
		for (int j = 0; j < (int)vec[i].size(); j++)mi = min(mi, d[vec[i][j]]);
		ans = max(ans, (ll)a[i] - mi);
		d[i] = min(mi, (ll)a[i]);
	}
	cout << ans << endl;
}

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

typedef long long int ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<ll, ll> Pair;
typedef vector<Pair> VP;
typedef vector<string> VS;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n); i >= 0; i--)
#define RREP(i, n, e) for(int i = (int)(n); i>= e; i--)
#define all(a) (a).begin(), (a).end()
#define VEC(n, x) VI n(x); rep(i, x) cin >> n[i];
#define MAT(m, x, y) VVI m(x, VI(y)); rep(i, x) rep(j, y) cin >> m[i][j];
#define FIX cout << fixed << setprecision(10);
#define out(x) cout << (x) << endl;
#define fin(x) { out(x); return 0; }
#define IN(x, l, r) ((l) <= (x) && (x) < (r))

template<class T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

void solve(VVI &G, VI &A, int v, int m, VI &res) {
  if (chmax(res[v], A[v] - m)) {
    for(auto nv: G[v]) solve(G, A, nv, min(m, A[v]), res);
  }
}

int main () {
  int N, M; cin >> N >> M;
  VEC(A, N);
  VI X(M), Y(M); rep(i, M) cin >> X[i] >> Y[i], X[i]--, Y[i]--;
  
  VVI G(N); rep(i, M) G[X[i]].push_back(Y[i]);
  vector<bool> start(N, true); rep(i, M) start[Y[i]] = false;
  
  VI res(N, INT_MIN);
  rep(i, N) if(start[i]) solve(G, A, i, INT_MAX, res);

  int ans = INT_MIN; rep(i, N) chmax(ans, res[i]);
  out(ans);
  
  return 0;
}
