#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> val(n);
  for (auto &i : val) cin >> i;
  vector<vector<int>> adj(n);
  for (int i = 1, u, v; i < n; ++i) {
    cin >> u >> v;
    --u, --v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  auto solve = [&](int mn) {
    auto w = [&](int u) { return val[u] >= mn; };
    vector<int> sz(n), dp(n), wsz(n), rdp(n);
    vector<multiset<int>> sub(n);
    for (int i = 0; i < n; ++i) sub[i].insert(0);
    function<void(int, int)> dfs = [&](int u, int p) {
      sz[u] = 1;
      wsz[u] = w(u);
      for (auto v : adj[u])
        if (v != p) {
          dfs(v, u);
          sz[u] += sz[v];
          wsz[u] += wsz[v];
          if (sz[v] == wsz[v])
            dp[u] += sz[v];
          else
            sub[u].insert(rdp[v]);
        }
      rdp[u] = (dp[u] + 1 + *sub[u].rbegin()) * w(u);
    };
    dfs(0, -1);
    int best = 0;
    function<void(int, int)> dfs2 = [&](int u, int p) {
      best = max(best, rdp[u]);
      for (auto v : adj[u])
        if (v != p) {
          int rdpu = rdp[u], rdpv = rdp[v];
          if (sz[v] == wsz[v])
            dp[u] -= sz[v];
          else
            sub[u].erase(sub[u].find(rdp[v]));
          sz[u] -= sz[v];
          wsz[u] -= wsz[v];
          rdp[u] = (dp[u] + 1 + *sub[u].rbegin()) * w(u);
          sz[v] += sz[u];
          wsz[v] += wsz[u];
          if (sz[u] == wsz[u])
            dp[v] += sz[u];
          else
            sub[v].insert(rdp[u]);
          rdp[v] = (dp[v] + 1 + *sub[v].rbegin()) * w(v);
          dfs2(v, u);
          rdp[v] = rdpv;
          if (sz[u] == wsz[u])
            dp[v] -= sz[u];
          else
            sub[v].erase(sub[v].find(rdp[u]));
          wsz[v] -= wsz[u];
          sz[v] -= sz[u];
          rdp[u] = rdpu;
          wsz[u] += wsz[v];
          sz[u] += sz[v];
          if (sz[v] == wsz[v])
            dp[u] += sz[v];
          else
            sub[u].insert(rdp[v]);
        }
    };
    dfs2(0, -1);
    return best;
  };
  int lo = 1, hi = 1e6;
  while (lo < hi) {
    int md = (lo + hi + 1) >> 1;
    if (solve(md) >= k)
      lo = md;
    else
      hi = md - 1;
  }
  cout << lo << "\n";
  return 0;
}
