#include<bits/stdc++.h>
using namespace std;
// #include <atcoder/all>
// using namespace atcoder;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n-1); i >= 0; i--)
#define all(v) (v).begin(),(v).end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T> T lcm(T a, T b) { return a/gcd(a,b)*b; }
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const ll MOD = 1e9+7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    vector<ll> dp(n, -LINF);
    vector<vector<int>> from(n);
    int x, y;
    rep(i,m) {
        cin >> x >> y;
        x--; y--;
        dp[x] = 0;
        from[y].push_back(x);
    }
    rep(i,n) {
        for (int j: from[i]) {
            dp[i] = max(dp[i], dp[j]+a[i]-a[j]);
        }        
    }
    ll ans = -LINF;
    rep(i,n) {
        // cout << dp[i] << endl;
        if (from[i].size()>0) ans = max(ans, dp[i]);
    }
    cout << ans << endl;
	return 0;
}
#include <bits/stdc++.h>      
using namespace std;            

#define  int               long long int
#define  ld                long double
#define  f(i,j,n)            for(int i = j; i <= n; i++)
#define  r(i,n,j)           for(int i = n; i >= j; i--)
#define  all(container)       container.begin() , container.end()
#define  sz(container)        (int)container.size()
#define  ff                first
#define  ss                second
#define  pii               pair <int , int>
#define  sp(x)              setprecision(x)
#define  mod              1000000007
#define  endl            "\n"
#define  pb              push_back
#define  mp             make_pair
#define  T             int ttt; cin >> ttt; while(ttt--)
#define fast           ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);

int power(int x, int y, int p)  
{  
    int res = 1;    
    x = x % p; 
    if (x == 0) return 0; 
    while (y > 0)  
    {     
        if (y & 1)  
            res = (res*x) % p;  
        y = y>>1; 
        x = (x*x) % p;  
    }  
    return res; 
}
int a[200005],b[200005],ans=-1e18;
bool vis[200005];
vector<int>v[200005];
void dfs(int r){
    vis[r]=1;
    for(auto i : v[r]){
        if(!vis[i]) 
            dfs(i);
        b[r]=max(b[r],b[i]);
        b[r]=max(b[r],a[i]);
    }
}

int32_t main()
{
    fast
    int n,m,x,y;    cin>>n>>m;
    f(i,1,n)    cin>>a[i];
    f(i,1,n)    b[i]=-1e16;
    f(i,1,m){
        cin>>x>>y;
        v[x].pb(y);
    }
    f(i,1,n)
        if(!vis[i])
            dfs(i);
    f(i,1,n)    
        ans=max(ans,b[i]-a[i]);
    cout<<ans;
}