#include <bits/stdc++.h>
using namespace std;
struct Tedge {
  int v, pre;
} edge[200010 * 2];
int n, k, en, cur[200010], val[200010], fa[200010], tot, h[200010], typ[200010],
    siz[200010], dis[200010], vst[200010];
int getint() {
  int x, f = 1;
  char ch;
  while (!isdigit(ch = getchar())) f = ch == '-' ? -1 : 1;
  x = ch - '0';
  while (isdigit(ch = getchar())) x = x * 10 + ch - '0';
  return f * x;
}
void addedge(int u, int v) {
  edge[++en] = (Tedge){v, cur[u]}, cur[u] = en;
  edge[++en] = (Tedge){u, cur[v]}, cur[v] = en;
}
bool dfs1(int p, int f, int now) {
  if (val[p] < now) return false;
  h[++tot] = p, siz[p] = 1, vst[p] = 1;
  bool blk = true;
  int ch = 0, wn = 0;
  for (int i = cur[p], v = edge[i].v; i; i = edge[i].pre, v = edge[i].v)
    if (v != f) {
      ch++;
      bool res = dfs1(v, p, now);
      blk &= res;
      if (res)
        siz[p] += siz[v];
      else
        wn++;
    }
  if (blk)
    typ[p] = 2;
  else if (!f && wn == 1) {
    typ[p] = 2;
    for (int i = cur[p], v = edge[i].v; i; i = edge[i].pre, v = edge[i].v)
      if (typ[v] == 2) siz[p] += siz[v];
    for (int i = cur[p], v = edge[i].v; i; i = edge[i].pre, v = edge[i].v)
      if (typ[v] == 1) siz[v] += siz[p];
  }
  return blk;
}
void dfs2(int p, int f) {
  if (!f)
    for (int i = cur[p], v = edge[i].v; i; i = edge[i].pre, v = edge[i].v)
      if (typ[v] == 1) f = p, p = v;
  int wn = 0;
  for (int i = cur[p], v = edge[i].v; i; i = edge[i].pre, v = edge[i].v)
    if (typ[v] == 1) wn++;
  if (wn == 1) {
    typ[p] = 2;
    for (int i = cur[p], v = edge[i].v; i; i = edge[i].pre, v = edge[i].v)
      if (typ[v] == 1) siz[v] += siz[p], dfs2(v, p);
  }
}
void dfs3(int p, int f, int d) {
  if (typ[p] != 1) return;
  dis[p] = (d += siz[p]);
  for (int i = cur[p], v = edge[i].v; i; i = edge[i].pre, v = edge[i].v)
    if (v != f) dfs3(v, p, d);
}
int find(int p) {
  dfs3(p, 0, 0);
  int ans = p;
  for (int i = 1; i <= tot; i++)
    if (typ[h[i]] == 1 && dis[h[i]] > dis[ans]) ans = h[i];
  return ans;
}
bool check(int now) {
  memset(vst, 0, sizeof(vst));
  for (int i = 1; i <= n; i++) typ[i] = val[i] >= now;
  for (int i = 1; i <= n; i++)
    if (typ[i] && !vst[i]) {
      tot = 0;
      dfs1(i, 0, now);
      if (typ[i] == 2) dfs2(i, 0);
      if (tot < k) continue;
      int wt = -1;
      for (int i = 1; i <= tot; i++)
        if (typ[h[i]] == 1) {
          wt = h[i];
          break;
        }
      if (wt == -1) return true;
      int x = find(wt);
      x = find(x);
      if (dis[x] >= k) return true;
    }
  return false;
}
int main() {
  (n = getint()), (k = getint());
  for (int i = 1; i <= n; i++) (val[i] = getint());
  for (int i = 1; i <= n - 1; i++) addedge(getint(), getint());
  int l = 0, r = 1000000, ans;
  while (l <= r)
    if (check(((l + r) >> 1)))
      ans = ((l + r) >> 1), l = ((l + r) >> 1) + 1;
    else
      r = ((l + r) >> 1) - 1;
  printf("%d\n", ans);
  return 0;
}
