#include <bits/stdc++.h>
using namespace std;
int n, k;
int A[200036], o[200036];
vector<int> G[200036];
int dp[200036], mx[200036], sd[200036], siz[200036], sz[200036];
void dfs(int u, int f) {
  siz[u] = o[u], sz[u] = 1;
  dp[u] = o[u];
  mx[u] = sd[u] = 0;
  vector<int> tr;
  for (int v : G[u])
    if (v != f) {
      dfs(v, u);
      siz[u] += siz[v], sz[u] += sz[v];
      if (o[u]) {
        if (siz[v] == sz[v])
          dp[u] += dp[v];
        else {
          if (dp[v] > mx[u])
            sd[u] = mx[u], mx[u] = dp[v];
          else if (dp[v] > sd[u])
            sd[u] = dp[v];
        }
      }
    }
  dp[u] = dp[u] + mx[u];
}
void pfs(int u, int f) {
  if (u != 1 && o[u]) {
    if (siz[u] == sz[u])
      dp[u] = (o[f] ? dp[f] : dp[u]);
    else if (siz[1] - siz[u] == sz[1] - sz[u])
      dp[u] += siz[1] - siz[u];
    else {
      int df = 0;
      if (dp[u] == mx[f])
        df = dp[f] - dp[u] + sd[f];
      else
        df = dp[f];
      if (df > mx[u]) dp[u] = dp[u] - mx[u] + df;
      if (df > mx[u])
        sd[u] = mx[u], mx[u] = df;
      else if (df > sd[u])
        sd[u] = df;
    }
  }
  for (int v : G[u])
    if (v != f) pfs(v, u);
}
int chk(int x) {
  for (int i = (1), iend = (n); i <= iend; ++i) o[i] = A[i] >= x;
  dfs(1, 1);
  pfs(1, 1);
  return *max_element(dp + 1, dp + 1 + n);
}
void solve() {
  cin >> n >> k;
  for (int i = (1), iend = (n); i <= iend; ++i) scanf("%d", A + i);
  for (int i = (2), iend = (n); i <= iend; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    G[u].push_back(v), G[v].push_back(u);
  }
  int l = 0, r = 1e6;
  while (r >= l) {
    int mid = l + r >> 1;
    if (chk(mid) >= k)
      l = mid + 1;
    else
      r = mid - 1;
  }
  cout << r << endl;
}
signed main() { solve(); }
