#include <bits/stdc++.h>
using namespace std;
int n, k, a[300001], s[300001], best;
vector<int> w[300001];
int dfs(int u, int p, int lim) {
  int cnt = s[u] = 1, max1 = 0, max2 = 0;
  for (int v : w[u])
    if (v != p) {
      int cur = dfs(v, u, lim);
      if (cur == s[v])
        cnt += cur;
      else if (cur > max1)
        max2 = max1, max1 = cur;
      else if (cur > max2)
        max2 = cur;
      s[u] += s[v];
    }
  if (a[u] < lim) return 0;
  best = max(best, cnt + max1 + max2);
  return cnt + max1;
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%d", a + i);
  for (int i = 1, x, y; i < n; i++)
    scanf("%d%d", &x, &y), w[x].push_back(y), w[y].push_back(x);
  int l = 1, r = 1000000, ans = 0;
  while (l <= r) {
    int m = (l + r) / 2;
    best = 0;
    dfs(min_element(a + 1, a + 1 + n) - a, 0, m);
    if (best >= k)
      l = m + 1, ans = m;
    else
      r = m - 1;
  }
  printf("%d\n", ans);
}
