#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 15;
vector<int> adj[N];
int a[N], sz[N], dirtysum[N], dp[N], tot[N];
int dfs(int x, int p, int n, int dt, int val) {
  int u, i;
  int m[2] = {0};
  int ret = 0;
  sz[x] = dp[x] = tot[x] = 1;
  dirtysum[x] = 0;
  for (i = 0; i < adj[x].size(); ++i) {
    u = adj[x][i];
    if (u != p)
      ret = max(ret, dfs(u, x, n, dt, val));
    else
      continue;
    if (tot[u] && tot[x])
      tot[x] += tot[u];
    else
      tot[x] = 0;
    sz[x] += sz[u];
    dp[x] += tot[u];
    dirtysum[x] += dirtysum[u];
    if (dp[u] - tot[u] > m[0]) {
      m[1] = m[0];
      m[0] = dp[u] - tot[u];
    } else if (dp[u] - tot[u] > m[1])
      m[1] = dp[u] - tot[u];
  }
  if (a[x] < val) {
    ++dirtysum[x];
    dp[x] = 0, tot[x] = 0;
    return ret;
  }
  dp[x] += m[0];
  ret = max(ret, dp[x] + m[1] + (dt == dirtysum[x] ? n - sz[x] : 0));
  return ret;
}
int main() {
  int x, y, n, k, i;
  cin >> n >> k;
  for (i = 1; i <= n; ++i) cin >> a[i];
  for (i = 0; i < n - 1; ++i) {
    scanf("%d%d", &x, &y);
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  int l = 1, r = 1e6, mid;
  while (l < r) {
    mid = (l + r + 1) / 2;
    int dt = 0;
    for (i = 1; i <= n; ++i)
      if (a[i] < mid) ++dt;
    if (dfs(1, 0, n, dt, mid) >= k)
      l = mid;
    else
      r = mid - 1;
  }
  cout << l << endl;
}
