#include <bits/stdc++.h>
#define pb push_back
#define int long long
using namespace std;
#define debug(args...) kout("[ " + string(#args) + " ]", args)
void kout() { cerr << endl; }
template <class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ',kout(b...); }
template <class T> void pary(T L, T R) { while (L != R) cerr << *L << " \n"[++L==R]; }

const int MAXN = 200000;
const int INF = 1e18;
int n, m;
int x, y;
int a[MAXN+1];
vector <int> path[MAXN+1];
int mmin[MAXN+1];
int ans = -INF;

signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  for (int i = 0; i < m; i++) {
    cin >> x >> y;
    path[x].pb(y);
  }
  for (int i = 1; i <= n; i++)
    mmin[i] = INF;
  for (int i = 1; i <= n; i++) {
    if (mmin[i] != INF)
      ans = max(ans, a[i] - mmin[i]);
    mmin[i] = min(mmin[i], a[i]);
    for (int j : path[i])
      mmin[j] = min(mmin[j], mmin[i]);
  }
  cout << ans << "\n";
}

        #include <bits/stdc++.h>
        using namespace std;
        #include <math.h>
        #include <iomanip>
        #include <cstdint>
        #include <string>
        #include <sstream>
        template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
        template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
        #define rep(i,n) for (int i = 0; i < (n); ++i)
        typedef long long ll;
        using P=pair<int,int>;
        const int INF=1001001001;
        const int mod=1e9+7;
        
        int main(){
          int n,m;
          cin>>n>>m;
          vector<ll>a(n);
          rep(i,n){cin>>a[i];}
          vector<vector<int>>G(n);
          rep(i,m){
            int x,y;
            cin>>x>>y;
            x--;y--;
            G[x].push_back(y);
          }
          vector<ll>buy(n,1e18);
          ll ans=-1e18;
          rep(i,n){
            chmax(ans,a[i]-buy[i]);
            for(int u:G[i]){
              chmin(buy[u],min(buy[i],a[i]));
            }
          }
          cout<<ans<<endl;
          return 0;
        }
