#include <bits/stdc++.h>
using namespace std;
const int N = 514514;
struct edge {
  int y, nt;
} e[N << 1];
int n, k, tot, mx, ct, m, as;
int w[N], a[N], b[N], hd[N], f[N], sz[N], si[N], s[N];
void add(int x, int y) {
  e[++tot] = {y, hd[x]};
  hd[x] = tot;
}
void ycl(int x, int f) {
  sz[x] = 1;
  for (int l = hd[x], y; l; l = e[l].nt) {
    y = e[l].y;
    if (y == f) continue;
    ycl(y, x);
    sz[x] += sz[y];
  }
}
void dfs(int x, int fa, int mi) {
  si[x] = (w[x] >= mi);
  int an = 1, mx1 = 0, mx2 = 0;
  for (int l = hd[x], y; l; l = e[l].nt) {
    y = e[l].y;
    if (y == fa) continue;
    dfs(y, x, mi);
    si[x] += si[y];
    if (si[y] == sz[y])
      an += sz[y];
    else if (f[y] > mx1)
      mx2 = mx1, mx1 = f[y];
    else if (f[y] > mx2)
      mx2 = f[y];
  }
  if (w[x] < mi)
    f[x] = 0;
  else
    f[x] = an + mx1;
  if (ct - si[x] == n - sz[x]) an += n - sz[x];
  if (w[x] >= mi) mx = max(mx, an + mx1 + mx2);
}
bool check(int mi) {
  mx = 0;
  ct = n - s[mi - 1];
  dfs(1, 0, b[mi]);
  return mx >= k;
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%d", &w[i]), a[i] = b[i] = w[i];
  for (int i = 1, x, y; i < n; i++) scanf("%d%d", &x, &y), add(x, y), add(y, x);
  sort(b + 1, b + n + 1);
  sort(a + 1, a + n + 1);
  ycl(1, 0);
  m = unique(b + 1, b + n + 1) - b - 1;
  int l = 1, r = m;
  for (int j = 1, i = 1; j <= m; j++) {
    while (i <= n && a[i] == b[j]) i++;
    s[j] = i - 1;
  }
  while (l <= r) {
    int mi = (l + r) >> 1;
    if (check(mi))
      l = mi + 1, as = mi;
    else
      r = mi - 1;
  }
  printf("%d", b[as]);
}
