#include <bits/stdc++.h>
using namespace std;
const int N = 200100;
int n, k, x[N];
vector<int> v[N];
int d[N], lant[N], siz[N], elmin[N], nrr, nrel[N];
int sm, re;
void calcd(int nod, int p) {
  siz[nod] = 1;
  elmin[nod] = x[nod];
  nrel[nod] = (x[nod] >= sm);
  int smax = 0;
  multiset<int> h;
  for (vector<int>::iterator it = v[nod].begin(); it != v[nod].end(); ++it)
    if (*it != p) {
      calcd(*it, nod);
      nrel[nod] += nrel[*it];
      if (re) return;
      siz[nod] += siz[*it];
      elmin[nod] = min(elmin[nod], elmin[*it]);
      h.insert(lant[*it]);
    }
  if (x[nod] < sm) {
    d[nod] = lant[nod] = 0;
    return;
  }
  if (elmin[nod] >= sm) {
    lant[nod] = siz[nod];
    d[nod] = siz[nod];
    if (d[nod] >= k) {
      re = 1;
    }
    return;
  }
  int sum = 0;
  for (vector<int>::iterator it = v[nod].begin(); it != v[nod].end(); ++it)
    if (*it != p) {
      if (d[*it] == siz[*it]) {
        sum += siz[*it];
        h.erase(h.find(lant[*it]));
      }
    }
  smax = 0;
  int sm2 = 0;
  for (vector<int>::iterator it = v[nod].begin(); it != v[nod].end(); ++it)
    if (*it != p) {
      if (d[*it] != siz[*it]) {
        h.erase(h.find(lant[*it]));
        smax = max(smax, d[*it]);
        sm2 = max(sm2, lant[*it]);
        int aa = 0;
        if (!h.empty()) aa = *h.rbegin();
        if (nrr - nrel[nod] == n - siz[nod]) aa += n - siz[nod];
        if (d[*it] + aa + sum + 1 >= k) {
          re = 1;
          return;
        }
        h.insert(lant[*it]);
      }
    }
  d[nod] = sum + smax + 1;
  lant[nod] = sm2 + sum + 1;
  if (d[nod] >= k) {
    re = 1;
    return;
  }
}
bool ver(int smin) {
  memset(d, 0, sizeof(d));
  memset(lant, 0, sizeof(lant));
  memset(nrel, 0, sizeof(nrel));
  sm = smin;
  nrr = 0;
  for (int i = 1; i <= n; ++i)
    if (x[i] >= smin) ++nrr;
  re = 0;
  calcd(1, 0);
  return re;
}
int main() {
  int i;
  cin >> n >> k;
  for (i = 1; i <= n; ++i) scanf("%d", &x[i]);
  for (i = 1; i < n; ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    v[a].push_back(b);
    v[b].push_back(a);
  }
  int pas = (1 << 20);
  for (i = 0; pas; pas /= 2)
    if (ver(i + pas)) i += pas;
  cout << i;
  return 0;
}
