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

#define fo(i, n) for (i = 0; i < n; i++)
#define ll long long
#define si(x) scanf("%d", &x)
#define sl(x) scanf("%lld", &x)
#define ss(s) scanf("%s", s)
#define pi(x) printf("%d\n", x)
#define pl(x) printf("%lld\n", x)
#define ps(s) printf("%s\n", s)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define MI map<int,int>
#define MC map<char,int>
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for (auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define endl "\n"
#define deb(x) cout << #x << "=" << x << "\n"
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << "\n"
#define deb3(x, y, z) cout << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << "\n"
#define deb4(x, y, z, w) cout << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << "," << #w << "=" << w << "\n"
#define input(arr,n) for(i=0;i<n;i++) cin>>arr[i]
#define showarr(arr,n) for( i=0; i<n; i++) cout<<arr[i]<<" "; cout<<endl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pl> vpl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());

const int mod = 1000000007;
const int N = 3e5, M = N;
//=======================

vi g[N];
ll a[N];
vector<vector<int>> adj;
vector<int> vis;
vector<ll> all_cp;

ll ma = -LLONG_MAX;

void dfs(ll u)
{
	for (ll v : adj[u])
	{	//deb3(u, v, a[u - 1]);
		all_cp[v] = min({all_cp[v], a[u - 1], all_cp[u]});
	}
}

void solve()
{
	int i = 0, j = 0, n, m, k, flag = 0 , ans = 0, u, v;
	cin >> n >> m;
	ll CP = LLONG_MAX;
	adj.resize(n + 1);
	vis.resize(n + 1);
	all_cp.resize(n + 1);
	input(a, n);
	fo(i, m)
	{
		cin >> u >> v;
		adj[u].pb(v);
	}
	all_cp[0] = LLONG_MAX;
	fo(i, n)
	all_cp[i + 1] = LLONG_MAX;
	// fo(i, n + 1)
	// {
	// 	cout << i << "---> ";
	// 	fo(j, adj[i].size())
	// 	cout << adj[i][j] << " ";
	// 	cout << endl;
	// }
	for (i = 1; i <= n; i++)
	{
		dfs(i);
	}
	// fo(i, n)	cout << i + 1 << " " << vis[i + 1] << "   "; cout << endl;
	// fo(i, n)	cout << i + 1 << " " << all_cp[i + 1] << "   "; cout << endl;
	for (i = 1; i <= n; i++)
	{
		ma = max(a[i - 1] - all_cp[i], ma);
	}
	if (ma == -LLONG_MAX)
		cout << 0;
	else
		cout << ma;
}
int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	srand(chrono::high_resolution_clock::now().time_since_epoch().count());
	int t = 1;
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	//cin >> t;
	while (t--)
	{
		solve();
	}
	return 0;
}
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>
#include <iomanip>
#include <random>

#define FOR_LT(i, beg, end) for (decltype(end) i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (decltype(end) i = beg; i <= end; i++)
#define FOR_DW(i, beg, end) for (decltype(beg) i = beg; end <= i; i--)
#define REP(n)              for (decltype(n) repeat_index = 0; repeat_index < n; repeat_index++)

using namespace std;

template<typename T, size_t S>
T minval(const T(&vals)[S])
{
	T val = numeric_limits<T>::max();
	FOR_LT(i, 0, S) {
		val = min(val, vals[i]);
	}
	return val;
}

template<typename T, size_t S>
T maxval(const T(&vals)[S])
{
	T val = numeric_limits<T>::min();
	FOR_LT(i, 0, S) {
		val = max(val, vals[i]);
	}
	return val;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(20);

	int n, m; cin >> n >> m;
	vector<int64_t> vs(n + 1);
	vector<int64_t> dp(n + 1, INT64_MIN);
	FOR_LE(i, 1, n) {
		cin >> vs[i];
	}

	vector<vector<int>> es(n + 1);
	FOR_LT(i, 0, m) {
		int a, b; cin >> a >> b;
		es[a].push_back(b);
	}

	int64_t ans = INT64_MIN;
	FOR_LE(i, 1, n) {
		ans = max(ans, vs[i] + dp[i]);
		dp[i] = max(dp[i], -vs[i]);
		for (auto& p : es[i]) {
			dp[p] = max(dp[p], dp[i]);
		}
	}
	cout << ans << endl;

	return 0;
}
