#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

const int INF = 1001001001;

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

    vector<int> dp(n, 2*INF);
    vector<vector<int>> to(n);
    rep(i, m) {
        int x, y;
        cin >> x >> y;
        x--; y--;
        to[x].push_back(y);
    }
    int ans = -INF;
    rep(i, n) {
        ans = max(ans, a[i] - dp[i]);
        for (auto j : to[i]) {
            dp[j] = min(dp[j], dp[i]);
            dp[j] = min(dp[j], a[i]);
        }
    }
    cout << ans << endl;

    return 0;
}
/// Down with The Sickness
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#pragma GCC optimization ("unroll-loops")

#include "bits/stdc++.h"
using namespace std;

using ll = long long;
using ii = pair<int, int>;

#define pb push_back
#define F first
#define S second
#define f(i,a,b)  for(int i = a; i < b; i++)
#define all(a)  a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()

const int N = 2e5 + 5, LG = 19, MOD = 998244353;
int n;
vector<int> adj[N];
int dist[N];
int depth[N];
void dfs1(int node, int p) {

    for(auto x : adj[node]) {
        if(x == p)continue;
        dist[x] = dist[node] + 1;
        dfs1(x, node);
    }

}
void dfs2(int node, int p) {

    for(auto x : adj[node]) {
        if(x == p)continue;
        dfs2(x, node);
        depth[node] = max(depth[node], depth[x] + 1);
    }

}
int cnt = 1;
int E[N];
void dfs3(int node, int p) {

    vector<ii> ans;
    E[node] = cnt;

    for(auto to : adj[node])
    if(to != p) {
        ans.pb(ii(depth[to], to));
    }

    sort(ans.begin(), ans.end());
    for(auto to : ans) {
        cnt++;
        dfs3(to.S,node);
        cnt++;
    }

}
int main(){
#ifdef ONLINE_JUDGE
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif // ONLINE_JUDGE

    cin >> n;

    f(i,1,n) {
        int u, v;
        cin >> u >> v;
        adj[u].pb(v);
        adj[v].pb(u);
    }

    dfs1(1,1);
    int mx = 1;
    f(i,2,n+1)
        if(dist[mx] < dist[i])
            mx = i;
    dfs2(mx,mx);
    dfs3(mx,mx);
    f(i,1,n+1)
        cout << E[i] << ' ';


    return 0;
}
