#include <iostream>
#include <vector>
#include <limits>
#include <cstring>
#include <time.h>
#include <math.h>
#include <algorithm>
#include <random>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <chrono>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vi;
typedef pair<ll, ll> pii;
typedef vector<pii > vii;
typedef vector<vector<ll> > vvi;
typedef vector<vvi > vvvi;
typedef vector<vector<pair<ll, ll> > > vvii;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,s,e) for(ll i=(s);i<(e);++i)
#define repr(i,s,e) for(ll i=(e);i>(s);--i)
#define io do { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } while (0)
#define endl '\n'
#define newl cout << '\n';

#define fill0(a) memset(a, 0, sizeof(a))
#define fill1(a) memset(a, -1, sizeof(a))

#define all(v) v.begin(), v.end()
#define bg begin()
#define ed end()
#define tr(it, v) for (auto it = v.bg; it != v.ed; it++)
#define prv(v) tr(it, v) { cout << *it << endl; }
#define prm(m) tr(it, m) { cout << it->first << " -> " << it->second << endl; }
#define scan(a, n) rep(i,0,n) cin >> a[i];
#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define sumv(v) *accumulate(all(v), 0)
#define ub(a, x) upper_bound(all(a), x)
#define lb(a, x) lower_bound(all(a), x)

ll min3(ll a, ll b, ll c) { return min(a, min(b, c)); }
ll max3(ll a, ll b, ll c) { return max(a, max(b, c)); }
ll mid3(ll a, ll b, ll c) { return a + b + c - min3(a, b, c) - max3(a, b, c); }
ll ceil1(ll x, ll y) { if(x % y) return (x + y) / y; else return x / y; }

const ll MOD = 1e9+7;
const ll INF = 1e18;
const ll TE3 = 1005;
const ll TE5 = 200005;
const string YN[2] = {"NO", "YES"};

using namespace std;

ll n, m;
ll v[TE5];
ll vis[TE5];
ll ma[TE5];
vi a[TE5];
ll ans = -INF;

ll dfs(ll x,ll p) {
	if(p!=INF) {
		ans = max(ans, v[x] - p);
	}
	if(vis[x]) {
		ans = max(ans, ma[x] - p);
		return ma[x];
	}
	vis[x] = 1;
	ll op = p;
	p = min(p, v[x]);
	ll ret = v[x];
	for (ll ne : a[x])
	{
		ret=max(ret,dfs(ne, p));
	}
	if(op!=INF) {
		ans = max(ans, ma[x] - op);
	}
	return ma[x]=ret;
}

int main()
{
	io;
	cin >> n >> m;
	fill1(ma);
	rep(i, 0, n)
	{
		cin >> v[i];
	}
	rep(i,0,m) {
		ll x, y;
		cin >> x >> y;
		--x;
		--y;
		a[x].pb(y);
	}
	rep(i,0,n) {
		if(!vis[i]) {
			dfs(i, INF);
		}
	}
	cout << ans << endl;
	return 0;
}

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

vector<vector<int>> edge;
vector<int> v;
vector<int> d;

int dfs(ll now, ll pre, ll target) {
    int res = 0;
    int ma = -1, mi = 1000000;
    int dma = -1, dmi = 1000000;
    int cnt = 0;
    for (int nxt : edge[now]) {
        if (nxt == pre) continue;
        cnt++;
        res += dfs(nxt, now, target);
        mi = min(mi, v[nxt]);
        ma = max(ma, v[nxt]);
        dmi = min(dmi, d[nxt]);
        dma = max(dma, d[nxt]);
    }
    d[now] = dmi+1;
    bool put = false;
    if (cnt == 0) {
        return 0;
    }else if (cnt == 1) {
        if (mi >= 2*target) {
            v[now] = 0;
            put = true;
        }else {
            v[now] = mi+1;
        }
    }else {
        if (ma+dmi+2 <= 2*target+1) {
            v[now] = mi+1;
        }else if (ma+1 >= 2*target+1){
            v[now] = 0;
            put = true;
        }else {
            v[now] = ma+1;
        }
    }
    if (now == 0 && !put) {
        if (v[now] > target) put = true;
    }
    if (put) {
        res++;
        d[now] = 0;
    }
    return res;
}

int main() {
    int N, K;
    cin >> N >> K;
    edge.resize(N);
    v.resize(N);
    d.resize(N);
    for (int i = 0; i < N-1; i++) {
        int u, v;
        cin >> u >> v;
        u--;v--;
        edge[u].push_back(v);
        edge[v].push_back(u);
    }
    
    ll l = 0, r = N;
    while (r-l > 1) {
        ll c = (l+r)/2;
        fill(v.begin(), v.end(), c+1);
        fill(d.begin(), d.end(), N*10);
        ll need = dfs(0, -1, c);
        //cout << need << endl;
        if (need <= K) r = c;
        else l = c;
    }
    cout << r << endl;
    
    return 0;
}