#include <bits/stdc++.h>
using namespace std;
int a[200000 + 5], n, k, ans;
vector<int> e[200000 + 5], vec;
int cnt[200000 + 5], sz[200000 + 5];
void dfs(int now, int fa, int x) {
  int mx[3] = {};
  cnt[now] = sz[now] = 1;
  for (auto v : e[now])
    if (v != fa) {
      dfs(v, now, x);
      sz[now] += sz[v];
      if (sz[v] == cnt[v])
        cnt[now] += sz[v];
      else {
        mx[2] = cnt[v];
        for (int i = 1; i >= 0; i--)
          if (mx[i + 1] > mx[i]) swap(mx[i], mx[i + 1]);
      }
    }
  cnt[now] += mx[0];
  if (a[now] < x) cnt[now] = 0;
  ans = max(ans, cnt[now] + mx[1]);
}
bool check(int x) {
  ans = 0;
  dfs(min_element(a + 1, a + n + 1) - a, 0, x);
  return ans >= k;
}
int lb(int l, int r) {
  r++;
  while (l < r) {
    int mid = (l + r) >> 1;
    if (check(vec[mid]) == 1)
      l = mid + 1;
    else
      r = mid;
  }
  return r - 1;
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= n - 1; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    e[u].push_back(v);
    e[v].push_back(u);
  }
  for (int i = 1; i <= n; i++) vec.push_back(a[i]);
  sort(vec.begin(), vec.end());
  vec.erase(unique(vec.begin(), vec.end()), vec.end());
  int N = vec.size();
  printf("%d\n", vec[lb(0, N - 1)]);
  return 0;
}
