#include<bits/stdc++.h>
using namespace std;
#define en      '\n'
#define endl    '\n'
#define ll      long long signed
#define pb      push_back
#define append  push_back
#define all(v)  (v).begin(),(v).end()
#define FOR(i,a,b,k) for(int i=a; k>0?i<b:i>b; i+=k)
#define fori(a) for(int i=0; i<a; i++)
#define forj(a) for(int j=0; j<a; j++)
#define fork(a) for(int k=0; k<a; k++)
#define MOD     1000000007
#define MAX     1000010
#define mset(a,s,k) memset(a,k,s*sizeof(a[0]))
#define ff      first
#define ss      second
#define __      <<" "<<
#define _       <<en
#define int ll
ll pow_(ll a,ll e,ll m=MOD){ll r=1;while(e){if(e&1)r=r*a%m;a=a*a%m;e>>=1;}return r;} 
int inv(ll a) {return (int)(pow_(a,MOD-2,MOD));}int add(ll a, ll b){return (a+b+MOD)%MOD;} int mul(ll a, ll b)
{return (MOD+a*b%MOD)%MOD;}int di(ll a, ll b){return mul(a,inv(b));}ll  ceil(ll a,ll b){return a/b+(a%b!=0);}
template<typename T1,typename T2>ostream&operator<<(ostream&O,pair<T1,T2>a){O<<"( ";O<<a.ff<<", "<<a.ss;O<<" )";return O;}
template<typename T>ostream&operator<<(ostream&O,vector<T>V){O<<"[ ";fori(V.size())O<<V[i]<<(i==V.size()-1?"":", ");O<<" ]";return O;}
template<typename T>ostream&operator<<(ostream&O,set<T>S){O<<"{ ";for(T i:S)O<<i<<", ";O<<" }";return O;}
template<typename T1,typename T2>ostream&operator<<(ostream&O,map<T1,T2>S){O<<"{ ";for(auto i:S)O<<i<<", ";O<<" }";return O;}
template<typename T=int>class print{public:vector<T>V;print(vector<T>v){V=v;cout<<" <"<<V<<"> ";}
print(T*x,int N){fori(N)V.push_back(x[i]);cout<<" <"<<V<<"> ";}friend ostream&operator<<(ostream&O,print p){return O;}};

#define vi vector<int>
#define tp pair<int,int>

int arr[MAX]; int N,M;
void reset();
vector<int> G[MAX];
int mi[MAX];

int dfs(int x){
    int &r=mi[x];
    if(r==INT_MIN){
        for(auto i: G[x]){
            r=max(r,dfs(i));
        }
    }
    return max(r,arr[x]);
}

int solve(){
    cin>>N>>M;
    reset();
    fori(N){ cin>>arr[i];}
    fori(M){
        int a,b;
        cin>>a>>b;
        G[a-1].push_back(b-1);
    }
    int res=INT_MIN;
    fori(N){
        dfs(i);// res=max(res, dfs(i,INT_MAX));
    }
    // cout<<print(mi,N) _;
    fori(N){
        if(mi[i]!=INT_MIN)
            res=max(res,mi[i]-arr[i]);
    }
    cout<<res;
    return 0;
}

void reset(){
    fori(N) {
        G[i].clear();
        mi[i]=INT_MIN;
    }
    
    // Clear Vectors, maps, sets
    // Set default values of arr
}
 
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t=1;
    while(t--){
        solve();
        // cout<<solve()<<en;
        // cout<<(solve()?"Yes":"No")<<endl;
    }
    return 0;
}


#include <iostream>
#include <vector>
using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}


#define MOD		1000000007
#define INF     (ll)1e15
#define ll		long long int
#define pll		pair<ll, ll>
#define vll     vector<ll>
#define vpll    vector<pll>
#define pb		push_back
#define endl	'\n' // Remove if interactive
#define ff 		first
#define ss 		second
#define fastio 	ios_base::sync_with_stdio(false);cin.tie(NULL)
//#define all(v)  v.begin(), v.end()
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)

ll power(ll x, ll y) { ll ans = 1; x %= MOD; while (y) {if (y & 1)ans = (x * ans) % MOD; x = (x * x) % MOD; y >>= 1;} return ans;}
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};


//#include <algorithm>
//#include <map>
//#include <queue>
//#include <cstring>

//#include <bits/stdc++.h>

vll max_cost;
vll cost;
vector<vll> edges;

ll dfs(ll si) {
    if(max_cost[si] != -1)
        return max_cost[si];
    max_cost[si] = cost[si];
    for(ll ei : edges[si]) {
        max_cost[si] = max(max_cost[si], dfs(ei));
    }
    return max_cost[si];
}

void solve() {
    ll n, m;
    cin >> n >> m;
    max_cost.resize(n, -1);
    cost.resize(n);
    edges.resize(n);

    for(int i = 0; i < n; i++) {
        cin >> cost[i];
    }

    for(int i = 0; i < m; i++) {
        ll x, y;
        cin >> x >> y;
        --x,--y;
        edges[x].pb(y);
    }

    for(int i = 0; i < n; i++) {
        dfs(i);
    }

    ll ans = -INF;

    //debug(max_cost);

    for(int i = 0; i < n; i++) {
        for(ll ei : edges[i]) {
            ans = max(ans, max_cost[ei] - cost[i]);
        }
    }

    cout << ans << endl;
}

int main() {
    fastio;
    solve();
}

//4
//3
//100 200 300 450
//1 2
//2 3
//3 4

// 2 1 10 20 2 1
