#include <bits/stdc++.h>
using namespace std;
int n, k, a[200010], fst[200010], num, sz[200010], deg[200010], mx1[200010],
    mx2[200010], mx1n[200010], nfn[200010];
struct edge {
  int x, y, n;
} e[400010];
pair<int, int> es[200010];
bool v[200010], full[200010];
void ins(int x, int y) {
  e[++num] = {x, y, fst[x]};
  fst[x] = num;
}
void dfs1(int x, int f, int bound) {
  v[x] = 1;
  sz[x] = 1;
  int hh = 0;
  full[x] = 1;
  mx1[x] = 1;
  mx2[x] = 0;
  nfn[x] = 0;
  mx1n[x] = 0;
  int fnum = 0;
  for (int i = fst[x]; i; i = e[i].n) {
    int y = e[i].y;
    if (y == f || a[y] < bound) continue;
    dfs1(y, x, bound);
    sz[x] += sz[y];
    full[x] &= full[y];
    if (!full[y] && ~nfn[x]) {
      if (!nfn[x])
        nfn[x] = y;
      else
        nfn[x] = -1;
    }
    hh++;
    if (full[y])
      fnum += sz[y];
    else {
      if (mx1[y] + 1 > mx1[x]) {
        mx2[x] = mx1[x];
        mx1[x] = mx1[y] + 1;
        mx1n[x] = y;
      } else if (mx1[y] + 1 > mx2[x]) {
        mx2[x] = mx1[y] + 1;
      }
    }
  }
  if (hh != deg[x] - (f != 0)) {
    full[x] = 0;
    nfn[x] = -1;
  }
  mx1[x] += fnum;
  if (mx1n[x]) mx2[x] += fnum;
}
int dfs2(int x, int f, int fmx, bool ffull) {
  int fnum = 0;
  for (int i = fst[x]; i; i = e[i].n) {
    int y = e[i].y;
    if (y != f && full[y]) fnum += sz[y];
  }
  int ans, hh = 0, anss;
  if (ffull) {
    ans = fmx + mx1[x];
    hh = mx1n[x];
  } else {
    int fnum = 1;
    ans = fmx;
    for (int i = fst[x]; i; i = e[i].n) {
      int y = e[i].y;
      if (y == f) continue;
      if (full[y])
        fnum += sz[y];
      else if (mx1[y] > ans) {
        ans = mx1[y];
        hh = y;
      }
    }
    ans += fnum;
  }
  anss = ans;
  for (int i = fst[x]; i; i = e[i].n) {
    int y = e[i].y;
    if (full[y] || y == f) continue;
    ans = max(ans, dfs2(y, x, (y == hh ? anss - mx1[x] + mx2[x] : anss),
                        ffull && nfn[x] == y));
  }
  return ans;
}
int wk(int x) { return dfs2(x, 0, 0, 1); }
bool chk(int x) {
  memset(fst, 0, sizeof(fst));
  memset(v, 0, sizeof(v));
  num = 0;
  for (int i = 1; i < n; i++)
    if (a[es[i].first] >= x && a[es[i].second] >= x) {
      ins(es[i].first, es[i].second);
      ins(es[i].second, es[i].first);
    }
  for (int i = 1; i <= n; i++)
    if (!v[i] && a[i] >= x) {
      dfs1(i, 0, x);
      if (sz[i] >= k && wk(i) >= k) return 1;
    }
  return 0;
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i < n; i++) {
    scanf("%d%d", &es[i].first, &es[i].second);
    deg[es[i].first]++;
    deg[es[i].second]++;
  }
  int l = 1, len = 1000000000;
  while (len) {
    int md = l + (len >> 1);
    if (chk(md)) {
      l = md + 1;
      len = len - (len >> 1) - 1;
    } else
      len >>= 1;
  }
  printf("%d\n", l - 1);
}
