#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n, k;
int a[N];
vector<int> g[N];
int ans = 0, cnt = 0;
int dp[N], big[N], bad[N];
void dfs(int u, int p, int x) {
  big[u] = 1, bad[u] = 0;
  if (a[u] < x)
    dp[u] = 0, bad[u] = 1;
  else
    dp[u] = 1;
  for (auto v : g[u]) {
    if (v == p) continue;
    dfs(v, u, x);
    bad[u] += bad[v];
    big[u] += big[v];
  }
  if (dp[u]) {
    int mx1 = 0, mx2 = 0;
    for (auto v : g[u]) {
      if (v == p) continue;
      if (dp[v] == big[v])
        dp[u] += dp[v];
      else {
        if (dp[v] > mx1) {
          mx2 = mx1, mx1 = dp[v];
        } else if (dp[v] > mx2)
          mx2 = dp[v];
      }
    }
    dp[u] += mx1;
    int now = dp[u] + mx2;
    if (bad[u] == cnt) now += n - big[u];
    ans = max(ans, now);
  }
}
bool check(int x) {
  cnt = 0, ans = 0;
  for (int i = (1); i < (n + 1); i++) {
    if (a[i] < x) cnt++;
  }
  dfs(1, 0, x);
  return ans >= k;
}
int main() {
  cin >> n >> k;
  for (int i = (1); i < (n + 1); i++) cin >> a[i];
  for (int i = (1); i < (n); i++) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  int s = 0, L = 1, R = 1e7;
  while (L <= R) {
    int mid = (L + R) / 2;
    if (check(mid)) {
      s = mid;
      L = mid + 1;
    } else
      R = mid - 1;
  }
  cout << s << "\n";
  return 0;
}
