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

template<typename T>
ostream& operator<<(ostream &os, vector<T> &v){
    string sep = " ";
    if(v.size()) os << v[0];
    for(int i=1; i<v.size(); i++) os << sep << v[i];
    return os;
}

template<typename T>
istream& operator>>(istream &is, vector<T> &v){
    for(int i=0; i<v.size(); i++) is >> v[i];
    return is;
}

#ifdef DBG
void debug_(){ cout << endl; }
template<typename T, typename... Args>
void debug_(T&& x, Args&&... xs){
    cout << x << " "; debug_(forward<Args>(xs)...);
}
#define dbg(...) debug_(__VA_ARGS__)
#else
#define dbg(...)
#endif

int main() {
    ios_base::sync_with_stdio(false);
    cout << setprecision(20) << fixed;

    int n, m; cin >> n >> m;
    vector<ll> a(n);
    cin >> a;

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

        g[y].push_back(x);
    }

    vector<ll> maxdp(n, -1e18);
    for(int i=n-1; i>=0; i--){
        for(int v: g[i]){
            maxdp[v] = max(maxdp[v], maxdp[i]);
            maxdp[v] = max(maxdp[v], a[i]);
        }
    }

    ll ans = -1e18;
    for(int i=0; i<n; i++){
        ans = max(ans, maxdp[i]-a[i]);
    }

    cout << ans << endl;
    
    return 0;
}
#include<bits/stdc++.h>
#define pb           push_back
#define pf           push_front
#define in           insert
#define ff           first
#define ss           second
#define int          long long
#define rep(i,x,m)   for(int i=x;i<m;i++)
#define MOD          1000000007
#define endl         "\n"
#define all(v)       v.begin(),v.end()
#define rall(v)      v.rbegin(),v.rend()
#define vi           vector<int>
#define pi           pair<int,int>
#define sz(x)       (int)x.size()
#define pq           priority_queue<int>
#define fix(y)       fixed<<setprecision(y)
#define print(v)     for(int i=0;i<v.size();i++) cout<<v[i]<<" ";cout<<endl
#define FIO         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

int power(int n,int m)
{int p=1;if(m==0)return 1;p=(power(n,m/2)%MOD);p=(p%MOD*p%MOD)%MOD;
return(m&1?((p%MOD*n%MOD)%MOD):(p%MOD));}
int n,m;
vi graph[200001];
int vis[200001];
vector<pi>v;
int cost[200001];
int mx=-1e15;

void dfs(int child,int par,int M)
{
    vis[child]=1;
    //cout<<child<<" "<<par<<endl;
    if(child!=par)
    mx=max(mx,cost[child]-M);

    for(auto x:graph[child])
    {

      mx=max(mx,cost[x]-M);
      if(vis[x]==0)
        dfs(x,child,M);
    }
}

void solve()
{
    cin>>n>>m;
    rep(i,1,n+1){
        int x;
        cin>>x;
        cost[i]=x;
        v.pb({x,i});
    }
    //cout<<n<<m<<endl;
    sort(all(v));
    rep(i,0,m)
    {
        int x,y;
        cin>>x>>y;
        graph[x].pb(y);
        

    }
    rep(i,0,n)
    {
        if(vis[v[i].ss]==0)
        {


            dfs(v[i].ss,v[i].ss,v[i].ff); 
        }
    }
    cout<<mx;


     

}

signed main()
{
        FIO
          
        
        int t=1;
        //cin>>t;
        while(t--)
        solve();
        cerr<<(float)clock()/CLOCKS_PER_SEC*1000<<" ms"<<endl;

        return 0;
}