#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = 1; i <= (int)(n); i++)
#define drep(i, n) for(int i = (n)-1; i >= 0; i--)
#define ALL(x) (x).begin(), (x).end()
#define dup(x,y) (((x)+(y)-1)/(y))
#define srep(i,s,t) for (int i = s; i < t; ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
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; }

const int mod = 1000000007;
// const int mod = 998244353;


int main() {
  int n, m;
  cin >> n >> m;
  vvi g(n);
  vi a(n);
  rep(i, n) cin >> a[i];
  rep(i, m) {
    int x, y;
    cin >> x >> y;
    --x; --y;
    g[x].push_back(y);
  }
  vi dp(n, INF*2);
  int ans = -INF;
  rep(i, n) {
    chmax(ans, a[i] - dp[i]);
    for (int j : g[i]) {
      chmin(dp[j], dp[i]);
      chmin(dp[j], a[i]);
    }
  }
  cout << ans << endl;
}
#include <bits/stdc++.h>
#define INF 1'000'000'000'000'000'000
#define MAX_N 200'000
#define MAX_M 200'000
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;

ll N, M;
ll A[MAX_N];
ll B[MAX_N];
ll X[MAX_M], Y[MAX_M];

void solve() {
  for (ll i = 0; i < N; ++i) {
    B[i] = A[i];
  }
  vector<pll> V;
  for (ll i = 0; i < M; ++i) {
    V.push_back({X[i], Y[i]});
  }
  sort(V.begin(), V.end());
  ll res = -INF;
  for (auto [x, y] : V) {
    res = max(res, A[y] - B[x]);
    B[y] = min(B[x], B[y]);
  }
  printf("%lld\n", res);
}

int main() {
  cin >> N >> M;
  for (ll i = 0; i < N; ++i) {
    cin >> A[i];
  }
  for (ll i = 0; i < M; ++i) {
    cin >> X[i] >> Y[i];
    --X[i];
    --Y[i];
  }
  solve();
}