#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > tree;
vector<int> val;
vector<int> dest;
vector<int> hasForbidden;
vector<int> DP;
vector<int> sum;
vector<int> notusing;
vector<int> maxForbidden;
vector<int> sMaxForbidden;
void compute(int edge, int lim) {
  if (DP[edge] != -1) return;
  int node = dest[edge], parent = dest[edge ^ 1];
  int &mf = maxForbidden[node];
  int &smf = sMaxForbidden[node];
  if (val[node] < lim) {
    hasForbidden[edge] = true;
    DP[edge] = 0;
    return;
  }
  hasForbidden[edge] = false;
  if (sum[node] == -1) {
    sum[node] = 1;
    notusing[node] = edge ^ 1;
    mf = -1;
    smf = -1;
    for (int i : tree[node])
      if (i != (edge ^ 1)) {
        compute(i, lim);
        if (hasForbidden[i]) {
          hasForbidden[edge] = true;
          if (mf == -1 || DP[mf] < DP[i]) {
            smf = mf;
            mf = i;
          } else if (smf == -1 || DP[smf] < DP[i]) {
            smf = i;
          }
        } else {
          sum[node] += DP[i];
        }
      }
    DP[edge] = sum[node] + ((mf == -1) ? 0 : DP[mf]);
    return;
  }
  if (notusing[node] != -1 && (notusing[node] ^ 1) != edge) {
    int i = notusing[node];
    notusing[node] = -1;
    compute(i, lim);
    if (hasForbidden[i]) {
      if (mf == -1 || DP[mf] < DP[i]) {
        smf = mf;
        mf = i;
      } else if (smf == -1 || DP[smf] < DP[i]) {
        smf = i;
      }
    } else {
      sum[node] += DP[i];
    }
  }
  DP[edge] = sum[node] + ((mf == -1) ? 0 : DP[mf]);
  if (hasForbidden[edge ^ 1]) {
    if (mf == (edge ^ 1)) {
      DP[edge] -= DP[mf];
      if (smf != -1) DP[edge] += DP[smf];
    }
  } else {
    DP[edge] -= DP[edge ^ 1];
  }
  hasForbidden[edge] = false;
  if (smf != -1) hasForbidden[edge] = true;
  if (mf != -1 && mf != (edge ^ 1)) hasForbidden[edge] = true;
}
int ans(int node, int lim) {
  if (val[node] < lim) return 0;
  int maxForbidden = 0;
  int ans = 1;
  for (int e : tree[node]) {
    compute(e, lim);
    if (hasForbidden[e])
      maxForbidden = max(maxForbidden, DP[e]);
    else
      ans += DP[e];
  }
  return ans + maxForbidden;
}
bool cando(int k, int me) {
  memset(DP.data(), -1, sizeof(int) * DP.size());
  memset(sum.data(), -1, sizeof(int) * sum.size());
  for (int i = 0; i < tree.size(); i++)
    if (ans(i, me) >= k) return true;
  return false;
}
int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  tree.resize(n);
  val.resize(n);
  dest.resize(2 * (n - 1));
  hasForbidden.resize(dest.size());
  DP.resize(dest.size());
  sum.resize(n);
  notusing.resize(n);
  maxForbidden.resize(n);
  sMaxForbidden.resize(n);
  for (int &x : val) scanf("%d", &x);
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    a--;
    b--;
    dest[2 * i] = a;
    dest[2 * i + 1] = b;
    tree[a].push_back(2 * i + 1);
    tree[b].push_back(2 * i);
  }
  auto tmp = val;
  sort(tmp.begin(), tmp.end());
  tmp.erase(unique(tmp.begin(), tmp.end()), tmp.end());
  int ans = 0;
  int m = 0;
  int M = tmp.size();
  while (M > m) {
    int me = (m + M) / 2;
    if (cando(k, tmp[me])) {
      ans = tmp[me];
      m = me + 1;
    } else {
      M = me;
    }
  }
  printf("%d\n", ans);
  return 0;
}
