#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 15;
vector<int> adj[N];
int dp[N], sz[N], a[N];
bool dirty[N], vis[N];
vector<int> order;
void dfs(int x, int p) {
  int u, i;
  sz[x] = 1;
  order.push_back(x);
  for (i = 0; i < adj[x].size(); ++i) {
    u = adj[x][i];
    if (u != p) dfs(u, x), sz[x] += sz[u];
  }
}
void dfs2(int x, int p) {
  int u, i, tot = 1, maxi = 0;
  vis[x] = 1;
  if (dirty[x]) {
    dp[x] = 0;
    return;
  }
  for (i = 0; i < adj[x].size(); ++i) {
    u = adj[x][i];
    if (u != p) {
      dfs2(u, x);
      if (dp[u] == sz[u])
        tot += sz[u];
      else
        maxi = max(maxi, dp[u]);
    }
  }
  dp[x] = maxi + tot;
}
bool dfs3(int x, int p, int Maxi, int n, int k) {
  if (vis[x]) return 0;
  vis[x] = 1;
  int u, i, tot = 1;
  multiset<int> s;
  multiset<int>::iterator it;
  multiset<int>::reverse_iterator rit;
  if (Maxi == 0 || n - sz[x] == Maxi)
    tot += Maxi;
  else
    s.insert(Maxi);
  for (i = 0; i < adj[x].size(); ++i) {
    u = adj[x][i];
    if (dirty[u] || u == p) continue;
    if (dp[u] == sz[u])
      tot += dp[u];
    else
      s.insert(dp[u]);
  }
  int a = 0, b = 0;
  if (s.size() > 0) a = *s.rbegin(), s.erase(s.find(a));
  if (s.size() > 0) b = *s.rbegin(), s.erase(s.find(b));
  if (tot + a + b >= k) return 1;
  if (a != 0) s.insert(a);
  if (b != 0) s.insert(b);
  for (i = 0; i < adj[x].size(); ++i) {
    u = adj[x][i];
    if (dirty[u] || u == p) continue;
    if (dp[u] == sz[u])
      tot -= dp[u];
    else {
      assert(s.size() > 0);
      it = s.find(dp[u]), s.erase(it);
    }
    int nMaxi = tot;
    if (s.size() > 0) nMaxi += *s.rbegin();
    if (dfs3(u, x, nMaxi, n, k)) return 1;
    if (dp[u] == sz[u])
      tot += dp[u];
    else
      s.insert(dp[u]);
  }
  return 0;
}
bool go(int n, int k, int val) {
  int i, u;
  for (i = 1; i <= n; ++i) {
    if (a[i] >= val)
      dirty[i] = 0;
    else
      dirty[i] = 1;
  }
  memset(vis, 0, sizeof(vis));
  for (i = 0; i < order.size(); ++i)
    if (!vis[order[i]]) dfs2(order[i], 0);
  memset(vis, 0, sizeof(vis));
  for (i = 0; i < order.size(); ++i)
    if (!vis[order[i]] && !dirty[order[i]]) {
      if (dfs3(order[i], 0, 0, n, k)) return 1;
    }
  return 0;
}
void solve() {
  int n, i, k, x, y;
  cin >> n >> k;
  for (i = 1; i <= n; ++i) scanf("%d", &a[i]);
  int l = 1, r = 1e6, mid;
  for (i = 0; i < n - 1; ++i)
    scanf("%d%d", &x, &y), adj[x].push_back(y), adj[y].push_back(x);
  dfs(1, 0);
  while (l < r) {
    mid = (l + r + 1) / 2;
    if (go(n, k, mid))
      l = mid;
    else
      r = mid - 1;
  }
  cout << l << endl;
}
int main() { solve(); }
