#include<bits/stdc++.h>
#define rep(i,a,b) for (int i = a; i < b; i++)
#define rrep(i,a,b) for (int i = a - 1; i >= b; i--)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define eb emplace_back
#define pb push_back
#define pvec(a) for (int i = 0; i < a.size(); i++) cout << a[i] << " "; cout << '\n'
#define wt(a) cout << a << '\n'
using namespace std;
using ll = long long;
template<class T, class U>bool chmin(T& a, U b) {if (a > b) {a = b; return 1;} return 0;}
template<class T, class U>bool chmax(T& a, U b) {if (a < b) {a = b; return 1;} return 0;}

vector<vector<int>> g(200005);
vector<bool> isl(200005, false);
const int INF = 1001001001;
vector<int> dp(200005, -1);
vector<int> A(200005);

int rec(int v, bool iss) {
    if (dp[v] != -1) return dp[v];
    int ret = (!iss ? -INF : A[v]);
    for (int nv: g[v]) {
        chmax(ret, rec(nv, true));
    }
    return dp[v] = ret;
}

int main() {
    int N, M;
    cin >> N >> M;
    
    rep (i, 0, N) cin >> A[i];
    rep (i, 0, M) {
        int X, Y;
        cin >> X >> Y;
        X--, Y--;
        g[X].pb(Y);
    }

    rep (i, 0, N) if (g[i].size() == 0) isl[i] = true;

    int ans = -INF;
    rep (i, 0, N) {
        if (isl[i]) continue;
        chmax(ans, rec(i, false) - A[i]);
    }

    wt(ans);
    return 0;
}
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <numeric>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

int main(void)
{
    int n, m;

    cin >> n >> m;

    vector<vector<ll>> g(n, vector<ll>());
    vector<P> a(n), _a;

    for (int i = 0; i < n; i++)
    {
        int x;
        cin >> x;
        a[i] = {x, i};
    }

    _a = a;

    sort(a.begin(), a.end());

    for (int i = 0; i < m; i++)
    {
        int x, y;
        cin >> x >> y;
        x--, y--;

        g[x].push_back(y);
    }

    vector<bool> searched(n, false);
    vector<ll> dp(n, INF);

    for (int i = 0; i < n; i++)
    {
        queue<int> q;
        q.push(a[i].second);
        ll x = a[i].first;

        while (q.size())
        {
            int p = q.front();
            q.pop();

            for (auto &&j : g[p])
            {
                if (searched[j])
                {
                    continue;
                }
                searched[j] = true;

                dp[j] = x;
                q.push(j);
            }
        }
    }

    ll ans = -INF;

    for (int i = 0; i < n; i++)
    {
        ans = max(ans, _a[i].first - dp[i]);
    }

    cout << ans << endl;
}
