#include <bits/stdc++.h>
using namespace std;
int N, K;
int A[200004];
vector<int> adj[200004];
namespace CJ {
int subtree_sz[200004];
void dfs_preprocess(int u, int p) {
  subtree_sz[u] = 1;
  for (int v : adj[u]) {
    if (v == p) continue;
    dfs_preprocess(v, u);
    subtree_sz[u] += subtree_sz[v];
  }
}
int LP1[200004];
int LP2[200004];
int sum_full[200004];
void dfs_down(int u, int p, int min_val) {
  sum_full[u] = 0;
  int max_len1 = 0, max_len2 = 0;
  for (int v : adj[u]) {
    if (v == p) continue;
    dfs_down(v, u, min_val);
    if (LP1[v] == subtree_sz[v]) {
      sum_full[u] += subtree_sz[v];
    } else if (max_len1 < LP1[v]) {
      max_len2 = max_len1;
      max_len1 = LP1[v];
    } else if (max_len2 < LP1[v])
      max_len2 = LP1[v];
  }
  LP1[u] = LP2[u] = 0;
  if (A[u] >= min_val) {
    LP1[u] = 1 + sum_full[u] + max_len1;
    if (!adj[u].empty()) LP2[u] = 1 + sum_full[u] + max_len2;
  }
}
void dfs_up(int u, int p, int min_val) {
  if (LP1[u] == subtree_sz[u]) return;
  if (p >= 0 && A[u] >= min_val && A[p] >= min_val) {
    if (LP1[p] == 1 + sum_full[p] + LP1[u]) {
      if (subtree_sz[1] - subtree_sz[u] == 1 + sum_full[p]) {
        sum_full[u] += 1 + sum_full[p];
        LP1[u] += 1 + sum_full[p];
        LP2[u] += 1 + sum_full[p];
      } else {
        int lp_up = 1 + sum_full[u] + LP2[p];
        if (LP1[u] < lp_up) {
          LP2[u] = LP1[u];
          LP1[u] = lp_up;
        } else if (LP2[u] < lp_up)
          LP2[u] = lp_up;
      }
    } else {
      int lp_up = 1 + sum_full[u] + LP1[p];
      if (LP1[u] < lp_up) {
        LP2[u] = LP1[u];
        LP1[u] = lp_up;
      } else if (LP2[u] < lp_up)
        LP2[u] = lp_up;
    }
  }
  for (int v : adj[u]) {
    if (v == p) continue;
    dfs_up(v, u, min_val);
  }
}
bool check(int min_val) {
  dfs_down(1, -1, min_val);
  if (LP1[1] == subtree_sz[1]) return LP1[1] >= K;
  dfs_up(1, -1, min_val);
  for (int u = 1; u <= N; ++u)
    if (LP1[u] >= K) return true;
  return false;
}
int solve() {
  dfs_preprocess(1, -1);
  vector<int> S(A + 1, A + 1 + N);
  sort(S.begin(), S.end());
  S.resize(unique(S.begin(), S.end()) - S.begin());
  int res = 0;
  int lo = 0, hi = int(S.size()) - 1;
  while (lo < hi) {
    int mid = lo + (hi - lo + 1) / 2;
    if (!check(S[mid]))
      hi = mid - 1;
    else
      lo = mid;
  }
  res = S[lo];
  return res;
}
}  // namespace CJ
int main(int argc, char* argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> N >> K;
  for (int i = 1; i <= N; ++i) cin >> A[i];
  for (int j = 1; j < N; ++j) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  cout << CJ::solve() << endl;
  return 0;
}
