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

typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FOR1(i, n) for(int (i)=1; (i)<=(n); (i)++)
#define FORI(i, n) for(int (i)=n-1; (i)>=0; (i)--)
template<class T, class U> void umin(T& x, const U& y){ x = min(x, (T)y);}
template<class T, class U> void umax(T& x, const U& y){ x = max(x, (T)y);}
template<class T, class U> void init(vector<T> &v, U x, size_t n) { v=vector<T>(n, (T)x); }
template<class T, class U, typename... W> void init(vector<T> &v, U x, size_t n, W... m) { v=vector<T>(n);  for(auto& a : v) init(a, x, m...); }

int n, m;
int main(int argc, char** argv) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << setprecision(15);
    if (argc == 2 && atoi(argv[1]) == 123456789) freopen("d:\\code\\cpp\\contests\\stdin", "r", stdin);

    cin >> n >> m;
    vector<int> a(n+1);
    FOR1(i, n) cin >> a[i];
    vector<vector<int>> edges(n+1);
    FOR(i, m){
        int u, v;
        cin >> u >> v;
        edges[v].push_back(u);
    }

    const ll inf = 1e9+1;
    vector<ll> dp(n+1, inf);
    ll sol = -1e9;
    FOR1(v, n){
        for(int u : edges[v])
            umin(dp[v], dp[u]);
        if (edges[v].size())
            umax(sol, (ll)a[v] - dp[v]);
        umin(dp[v], a[v]);
    }
    cout << sol << endl;

    if (argc == 2 && atoi(argv[1]) == 123456789) cout << clock()*1.0/CLOCKS_PER_SEC << " sec\n";
    return 0;
}


#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <functional>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <bitset>
#include <math.h>
#include <random>
#include <chrono>
#include <assert.h>
using namespace std ;
using ll = long long ;
using ld = long double ;
template<class T> using V = vector<T> ;
template<class T> using VV = V<V<T>> ;
using pll = pair<ll,ll> ;
#define all(v) v.begin(),v.end()
ll mod = 1000000007 ;
long double pie = acos(-1) ;
ll INF = 1e18 ;

void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
ll extGCD(ll a,ll b,ll &x,ll &y){
    if(b==0){
        x = 1 ;
        y = 0 ;
        return a ;
    }
    ll d = extGCD(b,a%b,y,x) ;
    y -= a/b*x ;
    return d ;
}
void fix_cout(){cout << fixed << setprecision(20) ;}
template<class T> void chmax(T &a,T &b){if(a<b) a = b ;}
template<class T> void chmin(T &a,T &b){if(a>b) a = b ;}

int main(){
    int n,m ;
    cin >> n >> m ;
    V<ll> c(n) ;
    for(auto &i:c) cin >> i ;
    VV<int> g(n) ;
    for(int i=0;i<m;i++){
        int a,b ;
        cin >> a >> b ;
        g[a-1].push_back(b-1) ;
    }
    V<ll> dp(n,INF) ;
    ll ans = -INF ;
    for(int i=0;i<n;i++){
        ans = max(ans,c[i]-dp[i]) ;
        c[i] = min(c[i],dp[i]) ;
        for(int j=0;j<g[i].size();j++){
            dp[g[i][j]] = min(dp[g[i][j]],c[i]) ;
        }
    }
    // for(auto i:dp) cout << i << " " ; cout << endl ;
    cout << ans << endl ;
}
