#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 233;
struct zs {
  int too, pre;
} e[maxn << 1];
int tot, last[maxn];
int tim[maxn], down[maxn], ful[maxn], sz[maxn];
bool val[maxn];
int i, j, k, n, m;
int KK, MNT;
bool FLAG;
int ra, fh;
char rx;
inline int read() {
  rx = getchar(), ra = 0, fh = 1;
  while ((rx < '0' || rx > '9') && rx != '-') rx = getchar();
  if (rx == '-') fh = -1, rx = getchar();
  while (rx >= '0' && rx <= '9') ra = ra * 10 + rx - 48, rx = getchar();
  return ra * fh;
}
inline void insert(int a, int b) {
  e[++tot].too = b, e[tot].pre = last[a], last[a] = tot, e[++tot].too = a,
  e[tot].pre = last[b], last[b] = tot;
}
inline void maxs(int &a, int b) {
  if (b > a) a = b;
}
void dfs(int x, int fa) {
  sz[x] = 1;
  int mx = 0;
  ful[x] = 0;
  for (int i = last[x], to; i; i = e[i].pre)
    if ((to = e[i].too) != fa) {
      dfs(to, x), sz[x] += sz[to];
      if (down[to] == sz[to])
        ful[x] += sz[to];
      else
        maxs(mx, down[to]);
    }
  val[x] = tim[x] >= MNT;
  if (!val[x])
    down[x] = ful[x] = 0;
  else
    down[x] = 1 + ful[x] + mx, ful[x]++;
  if (down[x] >= KK) FLAG = 1;
}
void dfs2(int x, int fa, int fup) {
  int i, to, fasz = n - sz[x], xup = fup == fasz ? down[x] + fup : ful[x] + fup;
  if (xup >= KK) {
    FLAG = 1;
    return;
  }
  if (!val[x]) {
    for (i = last[x]; i; i = e[i].pre)
      if ((to = e[i].too) != fa) dfs2(to, x, 0);
  } else {
    int mxp = 0, ndp = 0;
    for (i = last[x]; i; i = e[i].pre)
      if ((to = e[i].too) != fa && down[to] != sz[to]) {
        if (down[to] > down[mxp])
          ndp = mxp, mxp = to;
        else if (down[to] > down[ndp])
          ndp = to;
      }
    for (i = last[x]; i; i = e[i].pre)
      if ((to = e[i].too) != fa) {
        if (down[to] == sz[to])
          dfs2(to, x, xup - sz[to]);
        else if (fup != fasz)
          dfs2(to, x, ful[x] + max(fup, (to == mxp ? down[ndp] : down[mxp])));
        else
          dfs2(to, x, ful[x] + fup + (to == mxp ? down[ndp] : down[mxp]));
      }
  }
}
int main() {
  n = read(), KK = read();
  for (i = 1; i <= n; i++) tim[i] = read();
  for (i = 1; i < n; i++) insert(read(), read());
  int l = 1, r = 1e6, mid;
  while (l < r) {
    mid = MNT = (l + r + 1) >> 1;
    FLAG = 0;
    dfs(1, 0);
    if (!FLAG) dfs2(1, 0, 0);
    if (FLAG)
      l = mid;
    else
      r = mid - 1;
  }
  printf("%d\n", l);
}
