#include <iostream>
#include <vector>
//#include <string>
#include <algorithm>
//#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MOD 998244353
//#define MAX 200100
//#define NIL -1
#define INF 1000000000000000000
//const LL SEG_VAL = 1 << 19;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);

    LL N;
    LL M;
    cin >> N >> M;
    vector<LL> a(N);
    vector<vector<LL>> edge_f(N);
    vector<vector<LL>> edge_b(N);
    vector<LL> dp_min(N, INF);
    vector<LL> dp_max(N, 0);
    LL x;
    LL y;
    for(LL i=0; i<N; i++){
        cin >> a[i];
    }
    for(LL i=0; i<M; i++){
        cin >> x >> y;
        x--;
        y--;
        edge_f[x].push_back(y);
        edge_b[y].push_back(x);
    }

    for(LL i=0; i<N; i++){
        dp_min[i]=min(dp_min[i], a[i]);
        for(LL j=0; j<edge_f[i].size(); j++){
            dp_min[edge_f[i][j]]=min(dp_min[edge_f[i][j]], dp_min[i]);
        }
    }
    for(LL i=N-1; i>=0; i--){
        dp_max[i]=max(dp_max[i], a[i]);
        for(LL j=0; j<edge_b[i].size(); j++){
            dp_max[edge_b[i][j]]=max(dp_max[edge_b[i][j]], dp_max[i]);
        }
    }

    /*
    for(LL i=0; i<N; i++){
        cout << i << " " << dp_min[i] << " " << dp_max[i] << endl;
    }
    */

    LL ans=(-1)*INF;
    for(LL i=0; i<N; i++){
        for(LL j=0; j<edge_f[i].size(); j++){
            ans=max(ans, dp_max[edge_f[i][j]]-dp_min[i]);
        }
    }

    cout << ans << endl;

    return 0;
}

// ----- In the name of ALLAH, the Most Gracious, the Most Merciful -----

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

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define deb(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define int long long
#define endl "\n"
#define mod 1000000007
#define inf (int)1e18

const int mxn = 2e5+10;
vector<int> g[mxn];
bool vis[mxn];
int a[mxn];
vector<int> maxes(mxn,-1e14);

void dfs(int v){
    vis[v] = 1;

    for(int u : g[v]){
        if(!vis[u])
            dfs(u);
        maxes[v] = max(maxes[v],a[u]);
        maxes[v] = max(maxes[v],maxes[u]);
    }
}

int32_t main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

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

    for(int i=1;i<=m;i++){
        int u,v; cin >> u >> v;
        g[u].push_back(v);
    }

    int ans = -inf;

    for(int i=1;i<=n;i++){
        if(!vis[i]){
            dfs(i);
        }
    }

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

    cout << ans << endl;

    return 0;
}