#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
#define ff first 
#define ss second 

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>; 

const int oo = 1e9 +100;
const int maxn = 1e5+10;


int main(){
    int n, m;
    cin >> n >> m;
    vector<int> a(n+1), best(n+1, -oo);
    vector<vector<int>> p(n+1);

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

    for (int i=0; i<m; i++){
        int x, y;
        cin >> x >> y;
        p[y].push_back(x);
    }
    
    int ans = -oo;

    for (int i=n; i>=1; i--){
        for (auto pai: p[i]) best[pai] = max(best[pai], max(best[i], a[i]));
    }

    for (int i=1; i<=n; i++) {
        if (best[i] != -oo) ans = max(ans, best[i] - a[i]);
    }

    cout << ans << endl;
}
#include <bits/stdc++.h>

using namespace std;

#define f0r(a, b) for (long long a = 0; a < b; a++)
#define f1r(a, b, c) for (long long a = b; a < c; a++)
#define f0rd(a, b) for (long long a = b; a >= 0; a--)
#define f1rd(a, b, c) for (long long a = b; a >= c; a--)
#define ms(arr, v) memset(arr, v, sizeof(arr))
#define mp(a, b) make_pair(a, b)
#define pb push_back
#define f first
#define s second

#define ao(a, n) {for (int ele = 0; ele < n; ele++) { if (ele) cout << " "; cout << a[ele]; } cout << '\n';}

typedef long long ll;
typedef double ld;
typedef long double lld;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;


const ll inf = 1e16;

const int MOD = 1e9 + 7;
typedef decay<decltype(MOD)>::type T;
struct mi {
    T val;
    explicit operator T() const { return val; }
    mi() { val = 0; }
    mi(const long long& v) {
        val = (-MOD <= v && v <= MOD) ? v : v % MOD;
        if (val < 0) val += MOD; }
    friend ostream& operator<<(ostream& os, const mi& a) { return os << a.val; }
    friend bool operator==(const mi& a, const mi& b) { return a.val == b.val; }
    friend bool operator!=(const mi& a, const mi& b) { return !(a == b); }
    friend bool operator<(const mi& a, const mi& b) { return a.val < b.val; }
    mi operator-() const { return mi(-val); }
    mi& operator+=(const mi& m) {
        if ((val += m.val) >= MOD) val -= MOD;
        return *this; }
    mi& operator-=(const mi& m) {
        if ((val -= m.val) < 0) val += MOD;
        return *this; }
    mi& operator*=(const mi& m) { val = (long long) val * m.val % MOD;
        return *this; }
    friend mi pow(mi a, long long p) {
        mi ans = 1; assert(p >= 0);
        for (; p; p /= 2, a *= a) if (p & 1) ans *= a;
        return ans; }
    friend mi inv(const mi& a) { assert(a != 0); return pow(a, MOD - 2); }
    mi& operator/=(const mi& m) { return (*this) *= inv(m); }
    friend mi operator+(mi a, const mi& b) { return a += b; }
    friend mi operator-(mi a, const mi& b) { return a -= b; }
    friend mi operator*(mi a, const mi& b) { return a *= b; }
    friend mi operator/(mi a, const mi& b) { return a /= b; }
};

ll trade[200005];
vl graph[200005];

ll mx[200005];
ll vis[200005];

ll rec(ll v) {
    if (vis[v]) {
        return max(trade[v], mx[v]);
    }

    vis[v] = 1;


    ll m = -inf;

    for (ll u: graph[v]) {
        m = max(m, rec(u));
    }

    //cout << v << " " << m << " " << trade[v] << endl;
    mx[v] = m;

    return max(mx[v], trade[v]);
}


int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);

    ll n, m; cin >> n >> m;

    f0r(i, n) {
        cin >> trade[i];
    }

    f0r(i, m) {
        ll x, y; cin >> x >> y;
        x--; y--;
        graph[x].pb(y);
    }

    f0r(i, n) {
        sort(graph[i].begin(), graph[i].end());
        reverse(graph[i].begin(), graph[i].end());

    }

    ms(vis, 0);

    f0r(i, n) {
        if (!vis[i]) {
            rec(i);
        }
    }

    ll ret = -inf;

    f0r(i, n) {
        ret = max(ret, mx[i] - trade[i]);

    }

    cout << ret << endl;




}

