#include <bits/stdc++.h>
using namespace std;
const int MX = (1 << 18);
vector<int> v[MX];
int n, K;
int bad[MX], V[MX], par[MX];
int fakss[MX], good[MX], mx[MX];
void Pdfs(int x, int p) {
  good[x] = 1;
  int maxy = 0;
  for (auto nxt : v[x]) {
    if (nxt == p) continue;
    Pdfs(nxt, x);
    par[nxt] = x;
    fakss[x] |= fakss[nxt];
    if (fakss[nxt])
      maxy = max(maxy, good[nxt]);
    else
      good[x] += good[nxt];
  }
  good[x] += maxy;
  mx[x] = maxy;
  if (bad[x]) good[x] = mx[x] = 0;
}
bool nk7 = 0;
void dfs(int x, int flag, int cnt) {
  int G = good[x] - mx[x];
  if (flag == 0) {
    G += cnt;
    G += mx[x];
  } else
    G += max(mx[x], cnt);
  if (G >= K) nk7 = 1;
  int nflag = flag, cc = 0, ncnt, Good = 0, pp[2] = {0, 0};
  for (auto nxt : v[x]) {
    if (nxt == par[x]) continue;
    cc += fakss[nxt];
    if (!fakss[nxt])
      Good += good[nxt];
    else {
      pp[1] = max(pp[1], good[nxt]);
      if (pp[1] > pp[0]) swap(pp[1], pp[0]);
    }
  }
  for (auto nxt : v[x]) {
    if (nxt == par[x]) continue;
    cc -= fakss[nxt];
    if (!fakss[nxt]) Good -= good[nxt];
    nflag = flag ? flag : cc;
    ncnt = Good;
    int op = pp[0];
    if (fakss[nxt] && good[nxt] == pp[0]) op = pp[1];
    if (!flag) {
      ncnt += cnt;
      ncnt += op;
    } else
      ncnt += max(op, cnt);
    if (bad[x]) {
      nflag = 1;
      ncnt = 0;
    } else
      ncnt++;
    dfs(nxt, nflag, ncnt);
    cc += fakss[nxt];
    if (!fakss[nxt]) Good += good[nxt];
  }
}
bool check(int X) {
  for (int j = 1; j <= n; j++) {
    if (V[j] >= X)
      bad[j] = fakss[j] = 0;
    else
      bad[j] = fakss[j] = 1;
  }
  nk7 = 0;
  Pdfs(1, -1);
  dfs(1, 0, 0);
  return nk7;
}
int main() {
  scanf("%d %d", &n, &K);
  for (int j = 1; j <= n; j++) scanf("%d", &V[j]);
  for (int j = 1; j < n; j++) {
    int a, b;
    scanf("%d %d", &a, &b);
    v[a].push_back(b);
    v[b].push_back(a);
  }
  int st = 1, en = *max_element(V + 1, V + 1 + n), mid, ans;
  while (st <= en) {
    mid = (st + en) / 2;
    if (check(mid)) {
      ans = mid;
      st = mid + 1;
    } else
      en = mid - 1;
  }
  cout << ans << endl;
}
