#include <bits/stdc++.h>
using namespace std;
const int maxn = 202000;
int down[maxn], up[maxn];
int a[maxn], size[maxn];
bool ban[maxn];
vector<int> side[maxn];
multiset<int> q;
void dfs1(int u, int fa) {
  size[u] = 1;
  int buc = 0, mx = 0;
  for (int i = (0), iend = (side[u].size() - 1); i <= iend; i++) {
    int v = side[u][i];
    if (v == fa) continue;
    dfs1(v, u);
    size[u] += size[v];
    if (down[v] == size[v])
      buc += size[v];
    else {
      mx = max(mx, down[v]);
      q.insert(down[v]);
    }
  }
  if (!ban[u]) down[u] = 1 + buc + mx;
}
int n, k;
void dfs2(int u, int fa) {
  q.clear();
  int buc = 0;
  if (!ban[u]) up[u] = max(up[u], 1);
  for (int i = (0), iend = (side[u].size() - 1); i <= iend; i++) {
    int v = side[u][i];
    if (v == fa) continue;
    if (down[v] == size[v])
      buc += size[v];
    else {
      q.insert(down[v]);
    }
  }
  if (up[u] == n - size[u] + 1)
    buc += up[u] - 1;
  else {
    q.insert(up[u] - 1);
  }
  for (int i = (0), iend = (side[u].size() - 1); i <= iend; i++) {
    int v = side[u][i];
    if (v == fa) continue;
    if (down[v] == size[v])
      buc -= size[v];
    else {
      q.erase(q.find(down[v]));
    }
    if (!ban[u] && !ban[v]) {
      up[v] = buc + ((q.empty()) ? 0 : (*q.rbegin())) + 2;
    }
    if (down[v] == size[v])
      buc += size[v];
    else {
      q.insert(down[v]);
    }
  }
  for (int i = (0), iend = (side[u].size() - 1); i <= iend; i++) {
    int v = side[u][i];
    if (v == fa) continue;
    dfs2(v, u);
  }
}
bool check(int lim) {
  memset(down, 0, sizeof(down));
  memset(up, 0, sizeof(up));
  memset(ban, 0, sizeof(ban));
  for (int i = (1), iend = (n); i <= iend; i++)
    if (a[i] < lim) ban[i] = 1;
  dfs1(1, 0);
  dfs2(1, 0);
  for (int i = (1), iend = (n); i <= iend; i++) {
    int ans = 0;
    if (size[i] == down[i])
      ans = down[i] + up[i] - 1;
    else if (up[i] == n - size[i] + 1)
      ans = up[i] + down[i] - 1;
    else
      ans = max(up[i], down[i]);
    if (ans >= k) return 1;
  }
  return 0;
}
int main() {
  ios::sync_with_stdio(0);
  cin >> n >> k;
  for (int i = (1), iend = (n); i <= iend; i++) cin >> a[i];
  for (int i = (1), iend = (n - 1); i <= iend; i++) {
    int u, v;
    cin >> u >> v;
    side[u].push_back(v);
    side[v].push_back(u);
  }
  int l = 0, r = 1000001;
  while (l < r) {
    int mid = (l + r + 1) >> 1;
    if (check(mid))
      l = mid;
    else
      r = mid - 1;
  }
  cout << l;
  return 0;
}
