#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 6.66;
vector<int> tree[MAXN];
int arr[MAXN];
int dp1[MAXN];
int dp2[MAXN];
int sz[MAXN];
pair<int, int> s[MAXN][2];
int n;
int init_dfs(int v, int p = 0) {
  sz[v] = 1;
  for (auto u : tree[v])
    if (u != p) sz[v] += init_dfs(u, v);
  return sz[v];
}
inline void insert(int v, pair<int, int> x) {
  for (int i = 0; i < 2; i++)
    if (x > s[v][i]) swap(s[v][i], x);
}
void dfs_up(int v, int m, int p = 0) {
  dp1[v] = (arr[v] >= m);
  ;
  for (auto u : tree[v]) {
    if (u == p) continue;
    dfs_up(u, m, v);
    if (dp1[v] && dp1[u] == sz[u])
      dp1[v] += sz[u];
    else if (dp1[v])
      insert(v, make_pair(dp2[u], u));
  }
  if (dp1[v]) dp2[v] = dp1[v] + s[v][0].first;
}
void dfs_down(int v, int m, int up = 0, int p = 0) {
  if (arr[v] < m) {
    for (auto u : tree[v])
      if (u != p) dfs_down(u, m, 0, v);
    return;
  }
  if (up == n - sz[v])
    dp1[v] += up;
  else
    insert(v, make_pair(up, p));
  dp2[v] = dp1[v] + s[v][0].first;
  for (auto u : tree[v])
    if (u != p)
      dfs_down(u, m,
               dp2[v] - (sz[u] == dp1[u] ? dp1[u]
                                         : (u == s[v][0].second
                                                ? s[v][0].first - s[v][1].first
                                                : 0)),
               v);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> arr[i];
  for (int i = 1; i < n; i++) {
    int x, y;
    cin >> x >> y;
    tree[x].push_back(y);
    tree[y].push_back(x);
  }
  init_dfs(1);
  int l = 1, r = 1e6 + 1;
  while (l < r) {
    memset(dp1, 0, sizeof dp1);
    memset(dp2, 0, sizeof dp2);
    for (int i = 0; i < MAXN; i++) s[i][1] = s[i][0] = make_pair(0, 0);
    int mid = l + (r - l + 1) / 2;
    dfs_up(1, mid);
    dfs_down(1, mid);
    bool x = false;
    for (int i = 1; i <= n; i++) x |= dp2[i] >= k;
    if (x)
      l = mid;
    else
      r = mid - 1;
  }
  cout << l << endl;
  return 0;
}
