#include <bits/stdc++.h>
using namespace std;
long long n, k;
vector<long long> g[200002];
long long a[200002];
bool vis[200002], ok[200002];
long long good[200002];
long long upgood[200002], up[200002];
long long cnt[200002], down[200002], tail[200002];
void dfs1(long long node, long long par) {
  vis[node] = true;
  cnt[node] = 1;
  good[node] = true;
  tail[node] = 0;
  for (auto it : g[node]) {
    if (it == par) continue;
    if (!ok[it]) {
      good[node] = false;
      continue;
    }
    dfs1(it, node);
    if (!good[it]) {
      good[node] = false;
      tail[node] = max(tail[node], down[it]);
    } else
      cnt[node] += cnt[it];
  }
  down[node] = (cnt[node] + tail[node]);
}
bool dfs2(long long node, long long par) {
  long long whole = cnt[node];
  if (upgood[node])
    whole += (up[node] + tail[node]);
  else
    whole += max(up[node], tail[node]);
  if ((whole) >= k) return true;
  long long cntbad;
  if (upgood[node])
    cntbad = 0;
  else
    cntbad = 1;
  long long t1 = 0, t2 = 0;
  if (!upgood[node]) t1 = up[node];
  for (auto it : g[node]) {
    if (it == par) continue;
    if (!ok[it]) {
      cntbad++;
      continue;
    }
    if (!good[it]) {
      cntbad++;
      if (down[it] >= t1) {
        t2 = t1;
        t1 = down[it];
      } else if (down[it] > t2)
        t2 = down[it];
    }
  }
  long long cntnew = cnt[node];
  if (upgood[node]) cntnew += up[node];
  for (auto it : g[node]) {
    if (it == par) continue;
    if (!ok[it]) continue;
    long long all = cntnew;
    if (!good[it]) {
      if (t1 == down[it])
        all += t2;
      else
        all += t1;
    } else {
      all = (all - cnt[it] + t1);
    }
    up[it] = all;
    if ((cntbad - (!good[it])) == 0)
      upgood[it] = true;
    else
      upgood[it] = false;
    if (dfs2(it, node)) return true;
  }
  return false;
}
bool bs(long long t) {
  for (long long i = 1; i <= n; i++) {
    if (a[i] >= t)
      ok[i] = 1;
    else
      ok[i] = 0;
    vis[i] = false;
  }
  for (long long i = 1; i <= n; i++)
    if (!vis[i] && ok[i]) {
      dfs1(i, -1);
      upgood[i] = true;
      up[i] = 0;
      if (dfs2(i, -1)) return true;
    }
  return false;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  for (long long i = 1; i <= n; i++) cin >> a[i];
  for (long long i = 1; i < n; i++) {
    long long x, y;
    cin >> x >> y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  long long lo = 1, hi = (1e6 + 1);
  while ((hi - lo) > 1) {
    long long mid = (lo + (hi - lo) / 2);
    if (bs(mid))
      lo = mid;
    else
      hi = mid;
  }
  cout << lo << "\n";
  return 0;
}
