#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int n, k, a[maxn], cnt[maxn], sz[maxn], bad[maxn], all;
vector<int> way[maxn];
bool ok[maxn];
bool dfs(int node, int dad) {
  sz[node] = 1;
  cnt[node] = ok[node];
  bad[node] = !ok[node];
  int mx = 0, mx2 = 0;
  for (int i = 0; i < (int)way[node].size(); i++) {
    int adj = way[node][i];
    if (adj == dad) continue;
    if (dfs(adj, node)) return 1;
    sz[node] += sz[adj];
    bad[node] += bad[adj];
    if (!ok[node] or !ok[adj]) continue;
    if (cnt[adj] == sz[adj])
      cnt[node] += cnt[adj];
    else {
      if (cnt[adj] >= mx) {
        mx2 = mx;
        mx = cnt[adj];
      } else if (cnt[adj] > mx2)
        mx2 = cnt[adj];
    }
  }
  cnt[node] += mx;
  if (ok[node])
    return cnt[node] + mx2 + (bad[node] == all ? n - sz[node] : 0) >= k;
  return 0;
}
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);
    way[x].push_back(y);
    way[y].push_back(x);
  }
  int bgn = 1, end = 1e6;
  while (bgn < end) {
    int mid = (bgn + end + 1) >> 1;
    all = 0;
    for (int i = 1; i <= n; i++) {
      ok[i] = a[i] >= mid;
      all += !ok[i];
    }
    if (dfs(1, 0))
      bgn = mid;
    else
      end = mid - 1;
  }
  printf("%d\n", bgn);
  return 0;
}
