#include <bits/stdc++.h>
using namespace ::std;
const int N = 200000;
int n, k, ans;
int a[N + 5];
bool chk[N + 5];
int sorted_a[N + 5];
int preorder1[N + 5];
int preorder2[N + 5];
int group_size[N + 5];
int op;
int op_group_size[N + 5];
vector<int> ad[N + 5];
void input() {
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    sorted_a[i] = a[i];
  }
  sort(sorted_a, sorted_a + n);
  for (int i = 1; i < n; i++) {
    int v1, v2;
    scanf("%d %d", &v1, &v2);
    v1--, v2--;
    ad[v1].push_back(v2);
    ad[v2].push_back(v1);
  }
}
void dfs(int now, int lim) {
  chk[now] = true;
  int p1 = 0, p2 = 0, p3 = 0;
  group_size[now] = 1;
  op_group_size[now] = 0;
  for (auto next : ad[now]) {
    if (!chk[next]) {
      dfs(next, lim);
      op_group_size[now] += op_group_size[next];
      group_size[now] += group_size[next];
      if (preorder1[next] == group_size[next])
        p1 += preorder1[next];
      else if (preorder1[next] > p2)
        p3 = p2, p2 = preorder1[next];
      else if (preorder1[next] > p3)
        p3 = preorder1[next];
    }
  }
  if (a[now] >= lim) op_group_size[now]++;
  if (a[now] < lim)
    preorder1[now] = preorder2[now] = 0;
  else
    preorder1[now] = p1 + p2 + 1, preorder2[now] = p1 + p2 + p3 + 1;
  if (a[now] >= lim) {
    ans = max(ans, preorder2[now]);
    if (op_group_size[now] + n - group_size[now] == op)
      ans = max(ans, preorder2[now] + n - group_size[now]);
  }
}
bool possible(int v) {
  ans = 0;
  for (int i = 0; i < n; i++) chk[i] = false;
  dfs(0, v);
  if (n > 100) {
    for (int i = 0; i < n; i++) chk[i] = false;
    dfs(100, v);
  }
  if (n > 109000) {
    for (int i = 0; i < n; i++) chk[i] = false;
    dfs(108999, v);
  }
  return ans >= k;
}
int main() {
  input();
  int l = 0, r = n;
  while (l + 1 < r) {
    int mid = (l + r) / 2;
    op = n - mid;
    if (possible(sorted_a[mid]))
      l = mid;
    else
      r = mid;
  }
  printf("%d", sorted_a[l]);
  return 0;
}
