#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10, MOD = 1e9 + 7, MAX = 1e6 + 1;
vector<int> g[maxn];
int dp_up[maxn], dp_down[maxn], child[maxn], a[maxn], n, k, u, v;
bool mark_up[maxn], mark_down[maxn];
inline void Fix() {
  memset(dp_down, 0, sizeof(dp_down));
  memset(dp_up, 0, sizeof(dp_up));
  memset(mark_up, 0, sizeof(mark_up));
  memset(mark_down, 0, sizeof(mark_down));
  memset(child, 0, sizeof(child));
}
void dfs_down(int u, int p, int m) {
  int mx = 0, sum = 0;
  dp_down[u] = child[u] = 1;
  for (int v : g[u])
    if (v != p) {
      dfs_down(v, u, m);
      child[u] += child[v];
      if (mark_down[v])
        sum += dp_down[v];
      else
        mx = max(mx, dp_down[v]);
    }
  dp_down[u] += sum + mx;
  if (a[u] < m) dp_down[u] = 0;
  if (dp_down[u] == child[u]) mark_down[u] = true;
}
void dfs_up(int u, int p, int m) {
  int mx1 = 0, mx2 = 0, sum = 1;
  if (a[u] < m) {
    dp_up[u] = 0;
    for (int v : g[u])
      if (v != p) dfs_up(v, u, m);
    return;
  }
  if (dp_up[u] == n - child[u]) mark_up[u] = true;
  if (mark_up[u])
    sum += dp_up[u];
  else
    mx1 = dp_up[u];
  for (int v : g[u])
    if (v != p) {
      if (mark_down[v])
        sum += dp_down[v];
      else {
        if (dp_down[v] > mx1)
          mx2 = mx1, mx1 = dp_down[v];
        else if (dp_down[v] > mx2)
          mx2 = dp_down[v];
      }
    }
  for (int v : g[u])
    if (v != p) {
      if (mark_down[v])
        dp_up[v] = sum - dp_down[v] + mx1;
      else if (dp_down[v] == mx1)
        dp_up[v] = sum + mx2;
      else
        dp_up[v] = sum + mx1;
      dfs_up(v, u, m);
    }
}
inline bool solve() {
  for (int i = 0; i < n; i++) {
    if (mark_down[i] || mark_up[i]) {
      if (dp_down[i] + dp_up[i] >= k) return true;
    } else {
      if (max(dp_down[i], dp_up[i]) >= k) return true;
    }
  }
  return false;
}
inline bool check(int m) {
  Fix();
  dfs_down(0, 0, m);
  dfs_up(0, 0, m);
  return solve();
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n - 1; i++) {
    cin >> u >> v;
    u--, v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  int low = 0, high = MAX;
  while (high - low > 1) {
    int mid = (low + high) / 2;
    if (check(mid))
      low = mid;
    else
      high = mid;
  }
  cout << low;
  return 0;
}
