#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int n, k, a[N];
vector<int> adj[N];
int X;
bool good[N], res;
int dp[N][2];
void dfs(int u, int p) {
  for (int v : adj[u])
    if (v != p) dfs(v, u);
  if (a[u] < X) {
    good[u] = false;
    dp[u][0] = dp[u][1] = 0;
  } else {
    good[u] = true;
    int mx[2] = {0, 0}, safe = 1;
    vector<int> bad;
    for (int v : adj[u])
      if (v != p) {
        good[u] &= good[v];
        if (good[v])
          safe += dp[v][0];
        else {
          bad.push_back(v);
          if (dp[v][0] > mx[1]) mx[1] = dp[v][0];
          if (mx[0] < mx[1]) swap(mx[0], mx[1]);
        }
      }
    dp[u][0] = safe + mx[0];
    dp[u][1] = safe + mx[0] + mx[1];
    if (bad.size() == 1) {
      int v = bad[0];
      dp[u][1] = max(dp[u][1], safe + dp[v][1]);
    }
  }
  if (dp[u][1] >= k) res = true;
}
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; i++) scanf("%d", a + i);
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    u--;
    v--;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  int lo = 0, hi = 1e6 + 2;
  while (lo + 1 < hi) {
    X = (lo + hi) / 2;
    res = false;
    dfs(0, -1);
    if (res)
      lo = X;
    else
      hi = X;
  }
  printf("%d\n", lo);
  return 0;
}
