#include <bits/stdc++.h>
using namespace std;
const int MX = 2e5 + 5, MXX = 23;
const long long mod = 1e9 + 7, inf = 1e18 + 6;
int n, k, mn;
int a[MX], sr[MX], mx;
vector<int> G[MX];
bitset<MX> se1, se2;
int dp[MX], fx[MX];
void pre_dfs(int u) {
  se1[u] = 1;
  int mx_d = 0;
  for (auto v : G[u]) {
    if (a[v] < mn)
      fx[u] = mod;
    else if (!se1[v]) {
      pre_dfs(v);
      if (!fx[v])
        dp[u] += dp[v];
      else
        mx_d = max(mx_d, dp[v]), ++fx[u];
    }
  }
  dp[u] += mx_d + 1;
}
void dfs(int u, bool f = true, int val = 0) {
  se2[u] = 1;
  int co = 0, mx2 = 0, mx1 = 0;
  (f ? co += val : mx1 = max(mx1, val));
  for (auto v : G[u])
    if (mn <= a[v] && !se2[v]) {
      if (!fx[v])
        co += dp[v];
      else {
        if (mx1 < dp[v])
          mx1 = dp[v];
        else if (mx2 < dp[v])
          mx2 = dp[v];
      }
    }
  mx = max(mx, co + mx1 + 1);
  for (auto v : G[u])
    if (mn <= a[v] && !se2[v] && fx[v])
      dfs(v, f && (fx[u] == 1), co + (dp[v] == mx1 ? mx2 : mx1) + 1);
}
bool solv() {
  se1.reset();
  se2.reset();
  memset(fx, 0, sizeof fx);
  memset(dp, 0, sizeof dp);
  mx = 0;
  for (int i = 0; i < n; ++i)
    if (mn <= a[i] && !se1[i]) {
      pre_dfs(i);
      dfs(i);
      if (mx >= k) return true;
    }
  return false;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(9);
  cin >> n >> k;
  for (int i = 0; i < n; ++i) cin >> a[i], sr[i] = i;
  for (int i = 0; i < n - 1; ++i) {
    int u, v;
    cin >> u >> v;
    --u, --v;
    G[u].push_back(v), G[v].push_back(u);
  }
  sort(sr, sr + n, [](int i, int j) { return a[i] < a[j]; });
  int l = 0, r = n;
  while (l + 1 < r) {
    int md = (l + r) >> 1;
    mn = a[sr[md]];
    if (solv())
      l = md;
    else
      r = md;
  }
  cout << a[sr[l]] << "\n";
  return 0;
}
