#include <bits/stdc++.h>
using namespace std;
int n, k, mid, a[200010], sz[200010], siz[200010], dp1[200010];
vector<int> g[200010];
void dfs(int x, int fa) {
  sz[x] = (a[x] >= mid);
  siz[x] = dp1[x] = 1;
  int mx = 0;
  for (int i = 0, v; i < g[x].size(); i++) {
    v = g[x][i];
    if (v == fa) continue;
    dfs(v, x);
    sz[x] += sz[v];
    siz[x] += siz[v];
    if (sz[v] == siz[v])
      dp1[x] += siz[v];
    else
      mx = max(mx, dp1[v]);
  }
  dp1[x] += mx;
  if (a[x] < mid) dp1[x] = 0;
}
int anss, dp2[200010];
void dfs2(int x, int fa) {
  int nows = 1, mx = 0, bb = 0;
  if (sz[1] - sz[x] == n - siz[x])
    nows += n - siz[x];
  else
    mx = dp2[x], bb = fa;
  for (int i = 0, v; i < g[x].size(); i++) {
    v = g[x][i];
    if (v == fa) continue;
    if (sz[v] == siz[v])
      nows += siz[v];
    else if (mx < dp1[v])
      mx = dp1[v], bb = v;
  }
  nows += mx;
  if (a[x] >= mid) {
    anss = max(anss, nows);
    int mx2 = 0;
    for (int i = 0, v; i < g[x].size(); i++) {
      v = g[x][i];
      if (v == fa) continue;
      if (sz[v] == siz[v])
        dp2[v] = nows - sz[v];
      else if (v != bb)
        dp2[v] = nows, mx2 = max(mx2, dp1[v]);
    }
    if (bb != fa && sz[1] - sz[x] != n - siz[x]) mx2 = max(mx2, dp2[x]);
    dp2[bb] = nows - mx + mx2;
  }
  for (int i = 0; i < g[x].size(); i++)
    if (g[x][i] != fa) dfs2(g[x][i], x);
}
bool check() {
  for (int i = 1; i <= n; i++) dp1[i] = dp2[i] = 0;
  dfs(1, 0);
  anss = -1;
  dfs2(1, 0);
  return anss >= k;
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1, u, v; i < n; i++) {
    scanf("%d%d", &u, &v);
    g[u].push_back(v);
    g[v].push_back(u);
  }
  int l = 0, r = 1000000, ans;
  while (l <= r) {
    mid = (l + r) >> 1;
    if (check())
      ans = mid, l = mid + 1;
    else
      r = mid - 1;
  }
  printf("%d\n", ans);
  return 0;
}
