#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while ('0' <= ch && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  return x * f;
}
struct edge {
  int y;
  edge *n;
} e[400009], *fir[200009], *pt = e;
void AddE(int x, int y) { pt->y = y, pt->n = fir[x], fir[x] = pt++; }
int n, K, k[200009], v[200009], sz[200009], h[200009], f[200009];
bool Ans;
void dfs(int x) {
  sz[x] = 1;
  for (edge *p = fir[x]; p; p = p->n)
    if (p->y != h[x]) h[p->y] = x, dfs(p->y), sz[x] += sz[p->y];
}
void dfs1(int x) {
  int g = 0, mx = 0;
  for (edge *p = fir[x]; p; p = p->n)
    if (p->y != h[x]) {
      dfs1(p->y);
      if (f[p->y] == sz[p->y])
        g += f[p->y];
      else
        mx = max(mx, f[p->y]);
    }
  if (v[x])
    f[x] = g + mx + 1;
  else
    f[x] = 0;
}
void dfs2(int x) {
  int g = 0, mx = 0, sc = 0;
  for (edge *p = fir[x]; p; p = p->n) {
    if (f[p->y] == sz[p->y])
      g += f[p->y];
    else if (f[p->y] > f[mx])
      sc = mx, mx = p->y;
    else if (f[p->y] > f[sc])
      sc = p->y;
  }
  if (v[x] && 1 + g + f[mx] >= K) Ans = true;
  for (edge *p = fir[x]; p; p = p->n)
    if (p->y != h[x]) {
      int tmpf = f[x], tmpsz = sz[x];
      if (v[x]) {
        if (f[p->y] == sz[p->y])
          f[x] = 1 + f[mx] + g - f[p->y];
        else if (p->y != mx)
          f[x] = 1 + f[mx] + g;
        else
          f[x] = 1 + f[sc] + g;
        sz[x] = n - sz[p->y];
        dfs2(p->y);
        f[x] = tmpf, sz[x] = tmpsz;
      } else {
        f[x] = 0, sz[x] = n - sz[p->y];
        dfs2(p->y);
        f[x] = tmpf, sz[x] = tmpsz;
      }
    }
}
bool jub(int x) {
  for (int i = 1; i <= n; i++) v[i] = (k[i] >= x) ? 1 : 0;
  Ans = false;
  dfs1(1);
  dfs2(1);
  return Ans;
}
int main() {
  n = read(), K = read();
  for (int i = 1; i <= n; i++) k[i] = read();
  for (int i = 1; i <= n - 1; i++) {
    int x = read(), y = read();
    AddE(x, y);
    AddE(y, x);
  }
  dfs(1);
  int l = 1, r = 1e6;
  while (l < r) {
    int mid = (l + r) >> 1;
    if (jub(mid + 1))
      l = mid + 1;
    else
      r = mid;
  }
  printf("%d\n", l);
  return 0;
}
