#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void smin(T &a, U b) {
  if (a > b) a = b;
}
template <typename T, typename U>
inline void smax(T &a, U b) {
  if (a < b) a = b;
}
vector<int> adj[200200];
int n, k;
int dp[200200], sz[200200], val[200200], mx[200200][2], ans, mid;
void dfs(int u, int fa = 0) {
  mx[u][0] = mx[u][1] = dp[u] = 0;
  sz[u] = 1;
  for (int i = 0; i < adj[u].size(); i++) {
    int v = adj[u][i];
    if (v == fa) continue;
    dfs(v, u);
    sz[u] += sz[v];
    if (val[u] < mid) continue;
    if (dp[v] == sz[v])
      dp[u] += dp[v];
    else {
      smax(mx[u][1], dp[v]);
      if (mx[u][0] < mx[u][1]) swap(mx[u][0], mx[u][1]);
    }
  }
  dp[u] += mx[u][0];
  if (val[u] >= mid) dp[u]++;
}
void redfs(int u, int fa = 0, int pre = 0) {
  if (dp[u]) {
    if (pre == n - sz[u])
      smax(ans, dp[u] + pre);
    else
      smax(ans, dp[u] - mx[u][0] + max(mx[u][0], pre));
  }
  for (int i = 0; i < adj[u].size(); i++) {
    int v = adj[u][i];
    if (v == fa) continue;
    if (!dp[u])
      redfs(v, u, 0);
    else {
      if (dp[v] == sz[v]) {
        if (pre == n - sz[u])
          redfs(v, u, dp[u] - dp[v] + pre);
        else
          redfs(v, u, dp[u] - dp[v] - mx[u][0] + max(mx[u][0], pre));
      } else if (dp[v] == mx[u][0]) {
        if (pre == n - sz[u])
          redfs(v, u, dp[u] - dp[v] + pre);
        else
          redfs(v, u, dp[u] - dp[v] + max(mx[u][1], pre));
      } else {
        if (pre == n - sz[u])
          redfs(v, u, dp[u] + pre);
        else
          redfs(v, u, dp[u] - mx[u][0] + max(pre, mx[u][0]));
      }
    }
  }
}
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++) scanf("%d", val + i);
  int u, v;
  for (int i = 1; i < n; i++) {
    scanf("%d %d", &u, &v);
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  int st = 0, ed = 1000001;
  while (ed - st > 1) {
    mid = st + ed >> 1;
    ans = 0;
    dfs(1);
    redfs(1);
    if (ans >= k)
      st = mid;
    else
      ed = mid;
  }
  cout << st << endl;
  return 0;
}
