#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;
int n, k, m;
int a[200000];
bool q[200000];
vector<PII> g[200000];
int d[400000];
bool term[400000];
int s[400000], t[400000];
void dfs(int v, int p, int ind) {
if (d[ind] != -1) return;
if (!q[v]) {
term[ind] = true;
d[ind] = 0;
return;
}
term[ind] = false;
int mxterm = 0;
int rest = 0;
for (PII to : g[v]) if (to.first != p) {
dfs(to.first, v, to.second);
if (term[to.second]) {
term[ind] = true;
mxterm = max(mxterm, d[to.second]);
} else {
rest += d[to.second];
}
}
d[ind] = 1 + mxterm + rest;
}
bool solve(int x) {
REP(i, n) q[i] = a[i] >= x;
memset(d, -1, sizeof d);
memset(term, 0, sizeof term);
REP(i, m) if (d[i] == -1) {
dfs(t[i], s[i], i);
}
REP(i, n) if (q[i]) {
int mxterm = 0;
int rest = 0;
for (PII to : g[i]) {
if (term[to.second]) mxterm = max(mxterm, d[to.second]);
else rest += d[to.second];
}
if (1 + rest + mxterm >= k) return true;
}
return false;
}
int main() {
//freopen("input.txt", "r", stdin);
scanf("%d%d", &n, &k);
REP(i, n) scanf("%d", a + i);
REP(i, n - 1) {
int from, to;
scanf("%d%d", &from, &to), --from, --to;
g[from].pb(mp(to, 2 * i));
g[to].pb(mp(from, 2 * i + 1));
s[2 * i] = from;
t[2 * i] = to;
s[2 * i + 1] = to;
t[2 * i + 1] = from;
}
m = 2 * n - 2;
int lo = 1, hi = 1000000, mid;
while (lo < hi) {
mid = (lo + hi + 1) >> 1;
if (solve(mid)) lo = mid;
else hi = mid - 1;
}
printf("%d\n", lo);
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKI2RlZmluZSBwYiBwdXNoX2JhY2sKI2RlZmluZSBtcCBtYWtlX3BhaXIKI2RlZmluZSBSRVAoaSwgbikgZm9yIChpbnQg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WYgKGRbaV0gPT0gLTEpIHsKICAgICAgICBkZnModFtpXSwgc1tpXSwgaSk7CiAgICB9CiAgICBSRVAoaSwgbikgaWYgKHFbaV0pIHsKICAgICAgICBpbnQgbXh0ZXJtID0gMDsKICAgICAgICBpbnQgcmVzdCA9IDA7CiAgICAgICAgZm9yIChQSUkgdG8gOiBnW2ldKSB7CiAgICAgICAgICAgIGlmICh0ZXJtW3RvLnNlY29uZF0pIG14dGVybSA9IG1heChteHRlcm0sIGRbdG8uc2Vjb25kXSk7CiAgICAgICAgICAgIGVsc2UgcmVzdCArPSBkW3RvLnNlY29uZF07CiAgICAgICAgfQogICAgICAgIGlmICgxICsgcmVzdCArIG14dGVybSA+PSBrKSByZXR1cm4gdHJ1ZTsKICAgIH0KICAgIHJldHVybiBmYWxzZTsKfQoKaW50IG1haW4oKSB7CiAgICAvL2ZyZW9wZW4oImlucHV0LnR4dCIsICJyIiwgc3RkaW4pOwogICAgc2NhbmYoIiVkJWQiLCAmbiwgJmspOwogICAgUkVQKGksIG4pIHNjYW5mKCIlZCIsIGEgKyBpKTsKICAgIFJFUChpLCBuIC0gMSkgewogICAgICAgIGludCBmcm9tLCB0bzsKICAgICAgICBzY2FuZigiJWQlZCIsICZmcm9tLCAmdG8pLCAtLWZyb20sIC0tdG87CiAgICAgICAgZ1tmcm9tXS5wYihtcCh0bywgMiAqIGkpKTsKICAgICAgICBnW3RvXS5wYihtcChmcm9tLCAyICogaSArIDEpKTsKICAgICAgICBzWzIgKiBpXSA9IGZyb207CiAgICAgICAgdFsyICogaV0gPSB0bzsKICAgICAgICBzWzIgKiBpICsgMV0gPSB0bzsKICAgICAgICB0WzIgKiBpICsgMV0gPSBmcm9tOwogICAgfQogICAgbSA9IDIgKiBuIC0gMjsKICAgIGludCBsbyA9IDEsIGhpID0gMTAwMDAwMCwgbWlkOwogICAgd2hpbGUgKGxvIDwgaGkpIHsKICAgICAgICBtaWQgPSAobG8gKyBoaSArIDEpID4+IDE7CiAgICAgICAgaWYgKHNvbHZlKG1pZCkpIGxvID0gbWlkOwogICAgICAgIGVsc2UgaGkgPSBtaWQgLSAxOwogICAgfQogICAgcHJpbnRmKCIlZFxuIiwgbG8pOwogICAgcmV0dXJuIDA7Cn0K