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

int main(){
  ll N,X,Y,a=-1e18,i=0;cin>>N>>X;
  ll A[N+1],T[N+1],B[N+1];
  for(int i=1;i<=N;B[i]=A[i],T[i]=a,i++)cin>>A[i];
  vector<vector<int>>G(N+1);
  for(;cin>>X>>Y;)G[X].push_back(Y);
  for(i=1;i<=N;i++)for(auto v:G[i])T[v]=max(T[v],A[v]-B[i]),B[v]=min(B[v],B[i]);
  cout<<*max_element(T+1,T+N+1);
}
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define all(x) x.begin(),x.end()
#define LOL cout << '\n';
#define kill(x) {cout << (x) << '\n'; return;}
#define sz(x) ((int)x.size())
#define INF 1e15
#define NINF LONG_LONG_MIN
#define deb(x) cout << "[" << (#x) << "=" << x << "]" << '\n'
#define deb2(x,y) cout << "[" << (#x) << "=" << x << "] [" << (#y) << "=" << y << "]" << '\n'
#define deb3(x,y,z) cout << "[" << (#x) << "=" << x << "] [" << (#y) << "=" << y << "] [" << (#z) << "=" << z << "]" << '\n'

int n,m; 
const int N=2e5+69;
vector<int> adj[N];
int a[N];
vector<pair<int,int>> vis(N);
int OP=NINF;

pair<int,int> dfs(int s){
  if(vis[s].f!=-1 && vis[s].s!=-1) return vis[s];
  int ans=NINF,mx=0;
  for(auto &el:adj[s]){
    pair<int,int> T=dfs(el);
    ans=min(ans,T.f);
    mx=max(mx,T.s);
    //  deb3(s,ans,mx);
  }
  if(mx!=0) ans=max(ans,mx-a[s]);
  mx=max(mx,a[s]);
  //  deb3(s,ans,mx);
  OP=max(OP,ans);
  return vis[s]={ans,mx};
}

void solve(){
  cin>>n>>m;
  for(int i=1 ; i<=n ; i++) cin>>a[i],vis[i]={-1,-1};
  for(int i=0 ; i<m ; i++){
    int u,v; cin>>u>>v;
    adj[u].pb(v);
  }
  for(int i=1 ; i<=n ; i++){
    if(vis[i].f==-1 && vis[i].s==-1){
      dfs(i);
    }
  }

  cout<<OP;LOL
}

signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  int _ = 1; // cin >> _;
  for(int i = 1 ; i <= _ ; i++){
    // cout << "\nCase #" << i << ": \n";
    solve();
  }
  return 0;
}

// 1.77245