#include <bits/stdc++.h>
using namespace std;
int n, k, mc;
int s[200005], cb[200005], surv[200005], pure[200005];
pair<int, int> ffi[200005], sse[200005];
bool bad[200005];
vector<int> V[200005], V2[200005], V3[200005];
void dfs(int id, int prev) {
  for (int i = (0); i <= ((int)V[id].size() - 1); i++) {
    int to = V[id][i];
    if (to == prev) continue;
    dfs(to, id);
    cb[id] += cb[to];
    if (!cb[to])
      surv[id] += surv[to];
    else {
      if (ffi[id].first < surv[to]) {
        sse[id] = ffi[id];
        ffi[id] = make_pair(surv[to], to);
      } else if (sse[id].first < surv[to]) {
        sse[id] = make_pair(surv[to], to);
      }
    }
  }
  if (bad[id]) {
    pure[id] = surv[id] = 0;
  } else {
    pure[id] = ++surv[id];
    surv[id] += ffi[id].first;
  }
  for (int i = (0); i <= ((int)V[id].size() - 1); i++) {
    int to = V[id][i];
    if (to == prev) {
      V2[id][i] = 0;
      V3[id][i] = 0;
    } else if (!cb[to]) {
      V2[id][i] = (surv[id] - pure[to]);
      V3[id][i] = (pure[id] - pure[to]);
    } else {
      if (to == ffi[id].second)
        V2[id][i] = (pure[id] + sse[id].first);
      else
        V2[id][i] = (surv[id]);
      V3[id][i] = (pure[id]);
    }
  }
  return;
}
void dfs2(int id, int prev, int res) {
  if (prev == -1 || bad[id]) {
  } else {
    mc = max(mc, res + pure[id]);
    if (cb[id] == cb[1]) mc = max(mc, res + surv[id]);
    mc = max(mc, surv[id]);
  }
  for (int i = (0); i <= ((int)V[id].size() - 1); i++) {
    int to = V[id][i];
    if (to == prev) continue;
    if (bad[id])
      dfs2(to, id, 0);
    else if (cb[id] == cb[1])
      dfs2(to, id, res + V2[id][i]);
    else
      dfs2(to, id, max(V2[id][i], res + V3[id][i]));
  }
  return;
}
int bes(int m) {
  for (int i = (1); i <= (n); i++) {
    if (s[i] < m)
      bad[i] = true;
    else
      bad[i] = false;
    cb[i] = bad[i];
    ffi[i] = sse[i] = make_pair(0, 0);
    pure[i] = surv[i] = 0;
  }
  dfs(1, -1);
  mc = surv[1];
  dfs2(1, -1, 0);
  return mc;
}
int main() {
  scanf("%d %d", &n, &k);
  for (int i = (1); i <= (n); i++) scanf("%d", &s[i]);
  for (int i = (2); i <= (n); i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    V[a].push_back(b);
    V[b].push_back(a);
    V2[a].push_back(0);
    V2[b].push_back(0);
    V3[a].push_back(0);
    V3[b].push_back(0);
  }
  int l = 0, r = 1000001;
  while (r - l > 1) {
    int m = (l + r) >> 1;
    if (bes(m) >= k)
      l = m;
    else
      r = m;
  }
  printf("%d\n", l);
  return 0;
}
