#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
const int maxn5 = 2e5 + 10;
const int maxnt = 1.2e6 + 10;
const int maxn3 = 1e3 + 10;
const long long mod = 1e9 + 7;
const long long inf = 2e18;
int n, k, lim, mx[maxn5], mx2[maxn5], val[maxn5];
int cnt[maxn5], sz[maxn5], big[maxn5];
bool full[maxn5];
vector<int> adj[maxn5];
void dfs(int v, int par) {
  cnt[v] = 0, mx[v] = 0, mx2[v] = 0, big[v] = 0, full[v] = true;
  sz[v] = 1;
  for (auto u : adj[v])
    if (u != par) {
      dfs(u, v);
      full[v] &= full[u];
      if (full[u])
        big[v] += cnt[u];
      else if (cnt[u] >= mx[v])
        mx2[v] = mx[v], mx[v] = cnt[u];
      else
        mx2[v] = max(mx2[v], cnt[u]);
      sz[v] += sz[u];
    }
  cnt[v] = big[v] + mx[v];
  if (val[v] >= lim)
    cnt[v]++;
  else
    cnt[v] = 0, full[v] = false;
  return;
}
void rev_dfs(int v, int par) {
  if (val[v] >= lim)
    for (auto u : adj[v])
      if (u != par) {
        int now;
        if (full[u])
          now = big[v] + mx[v] - cnt[u] + 1;
        else {
          if (mx[v] == cnt[u])
            now = big[v] + mx2[v] + 1;
          else
            now = big[v] + mx[v] + 1;
        }
        if (now == n - sz[u])
          big[u] += now;
        else if (now >= mx[u])
          mx2[u] = mx[u], mx[u] = now;
        else
          mx2[u] = max(mx2[u], now);
      }
  for (auto u : adj[v])
    if (u != par) rev_dfs(u, v);
  return;
}
bool check(int mid) {
  lim = mid;
  dfs(1, -1);
  rev_dfs(1, -1);
  for (int i = 1; i <= n; i++)
    if (val[i] >= lim and big[i] + mx[i] + 1 >= k) return true;
  return false;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> val[i];
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  int lo = 1, hi = maxn;
  while (hi - lo > 1) {
    int mid = (lo + hi) >> 1;
    if (check(mid))
      lo = mid;
    else
      hi = mid;
  }
  cout << lo << endl;
  return 0;
}
