/*ॐ नमो भगवते वासुदेवाय नमः*/
#include<bits/stdc++.h>
using namespace std;

#define int long long
const int MOD = 1e9 + 7;
const double pi = 3.14159265359;

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

int binpow(int a, int b, int m) {
    a %= m;
    int res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
int inverse(int x){
    return binpow(x, MOD - 2, MOD);
}

void solve()
{
    int n, m;
    cin >> n >> m;
    vector<int> edge[n];
    vector<int> a(n);
    vector<int> vis(n);
    vector<int> pri(n, INT_MIN);
    for(auto & i : a)   cin >> i;
    while(m--){
        int x, y;
        cin >> x >> y;
        --x, --y;
        edge[x].push_back(y);
    }
    function<void(int)> dfs = [&](int x){
        vis[x] = 1;
        pri[x] = max(pri[x], a[x]);
        for(auto i : edge[x]){
            if(!vis[i])
                dfs(i);
            pri[x] = max(pri[x], pri[i]);
        }
    };
    for(int i = 0; i < n; i++){
        if(!vis[i]) dfs(i);
    }
    int ans = INT_MIN;
    for(int i = 0; i < n; i++){
        for(auto j : edge[i])
            ans = max(ans, pri[j] - a[i]);
    }
    cout << ans << endl;
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    solve();
    cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n ";
}
#include <bits/stdc++.h>
using namespace std;

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)

int main()
{
    lint n,m;cin >> n>>m;
    lint inf = 100000000000;
    vector<lint> a(n);
    REP(i, n)
        cin >> a[i];
        priority_queue<plint, vector<plint>, greater<plint>> q;
        REP(i, m)
        {
            lint x, y;
            cin >> x >> y;
            x--;y--;
        q.push(make_pair(x, y));
    }
    vector<lint> v(n,inf);
    lint ans = -inf;
    REP(i,m){
        plint xy = q.top();
        q.pop();
        lint from = xy.first, to = xy.second;
        if(v[from]==inf){
            v[from] = a[from];
        }else{
            v[from] = min(v[from], a[from]);
        }
        ans = max(ans, a[to] - v[from]);
        /*
        if(a[to]>v[from]){
            v[to] = v[from];
        }
        */
        v[to] = min({v[to], v[from], a[to]});
    }

    cout << ans << "\n";
    return 0;
}