#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
const long long inf = 1e18;
int a[maxn];
vector<int> g[maxn];
bool c[maxn], ok[maxn];
int dpdown[maxn], dpup[maxn];
int salem[maxn];
int mxdown[maxn], mxup[maxn];
int cnt[maxn];
int sum[maxn];
int n;
int dip[maxn];
void dfsdown(int v, int p) {
  ok[v] = c[v];
  cnt[v] = 1;
  sum[v] = c[v];
  for (auto u : g[v])
    if (u != p) dfsdown(u, v), cnt[v] += cnt[u], sum[v] += sum[u];
  if (!c[v]) return;
  for (auto u : g[v])
    if (u != p)
      if (ok[u])
        salem[v] += cnt[u];
      else {
        ok[v] = 0;
        mxdown[v] = max(mxdown[v], dpdown[u]);
      }
  dpdown[v] = mxdown[v] + salem[v] + 1;
}
void dfsup(int v, int p) {
  int _mx = -1;
  for (auto u : g[v])
    if (u != p && c[u] && c[v])
      mxup[u] = max(mxup[u], _mx), _mx = max(_mx, (1 - ok[u]) * dpdown[u]);
  reverse(g[v].begin(), g[v].end());
  _mx = -1;
  for (auto u : g[v])
    if (u != p && c[u] && c[v])
      mxup[u] = max(mxup[u], _mx), _mx = max(_mx, (1 - ok[u]) * dpdown[u]);
  for (auto u : g[v])
    if (u != p)
      if (c[u])
        if (c[v])
          if (sum[1] - sum[v] == n - cnt[v])
            dpup[u] = 1 + salem[v] - (ok[u] ? cnt[u] : 0) + mxup[u] + dpup[v];
          else
            dpup[u] =
                1 + salem[v] - (ok[u] ? cnt[u] : 0) + max(mxup[u], dpup[v]);
  for (auto u : g[v])
    if (u != p)
      if (c[u])
        if (c[v])
          if (sum[1] - sum[u] == n - cnt[u])
            dip[u] = 1 + salem[u] + dpup[u] + mxdown[u];
          else
            dip[u] = 1 + salem[u] + max(dpup[u], mxdown[u]);
  for (auto u : g[v])
    if (u != p) dfsup(u, v);
}
int check(int mid) {
  for (int i = 1; i <= n; ++i)
    dip[i] = salem[i] = ok[i] = cnt[i] = dpdown[i] = dpup[i] = mxup[i] =
        mxdown[i] = 0;
  for (int i = 1; i <= n; ++i) c[i] = (a[i] >= mid);
  dfsdown(1, 0);
  dfsup(1, 0);
  int mx = 0;
  for (int i = 1; i <= n; ++i)
    mx = max(max(mx, dip[i]), max(dpdown[i], dpup[i]));
  return mx;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int k;
  cin >> n >> k;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  for (int i = 1; i < n; ++i) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  int l = 1, r = 1e6 + 85;
  while (r - l > 1) {
    int mid = (l + r) / 2;
    if (check(mid) >= k)
      l = mid;
    else
      r = mid;
  }
  cout << l << endl;
  return 0;
}
