#include <bits/stdc++.h>
using namespace std;
struct ww {
  int a, b;
  void into(int x) {
    if (x > a)
      b = a, a = x;
    else
      b = max(b, x);
  }
  int lu(int x) { return a == x ? b : a; }
} h[200010];
int i, j, k, n, m, K, mid, _, s, an;
int a[200010], f[200010], ff[200010], g[200010], gg[200010];
vector<int> b[200010];
void dfs(int x, int y) {
  ff[x] = 1;
  s++;
  if (f[x]) _ = x;
  for (auto i : b[x]) {
    if (i == y || a[i] < mid) continue;
    dfs(i, x);
  }
}
void Dfs(int x, int y) {
  g[x] = 1;
  int you = f[x];
  for (auto i : b[x]) {
    if (i == y || a[i] < mid) continue;
    Dfs(i, x);
    g[x] += g[i];
    if (!g[i]) you = 1;
  }
  if (you) gg[x] = g[x], g[x] = 0;
}
void dp(int x, int y) {
  for (auto i : b[x]) {
    if (i == y || a[i] < mid || g[i]) continue;
    dp(i, x);
    h[x].into(h[i].a + gg[i]);
  }
}
void Dp(int x, int y) {
  an = max(an, gg[x] + h[x].a);
  for (auto i : b[x]) {
    if (i == y || a[i] < mid || g[i]) continue;
    ww A = h[x], B = h[i];
    int ge = h[x].lu(h[i].a + gg[i]);
    h[i].into(ge + gg[x]);
    Dp(i, x);
    h[i] = B, h[x] = A;
  }
}
inline int suan() {
  for (i = 1; i <= n; i++) {
    f[i] = ff[i] = g[i] = gg[i] = h[i].a = h[i].b = 0;
    for (auto j : b[i])
      if (a[j] < mid) f[i] = 1;
  }
  an = 0;
  for (i = 1; i <= n; i++)
    if (a[i] >= mid && !ff[i]) {
      _ = s = 0;
      dfs(i, 0);
      if (!_) {
        an = max(an, s);
        continue;
      }
      Dfs(_, 0);
      dp(_, 0);
      Dp(_, 0);
    }
  return an;
}
int main() {
  scanf("%d%d", &n, &K);
  for (i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (i = 1; i <= n - 1; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    b[x].push_back(y);
    b[y].push_back(x);
  }
  int l = 1, r = 1000000;
  for (; l <= r;) {
    mid = (l + r) / 2;
    if (suan() >= K)
      l = mid + 1;
    else
      r = mid - 1;
  }
  printf("%d\n", l - 1);
  return 0;
}
