#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int INF = 1000000001;
const long long int LLINF = 1000000000000000001LL;
void dfs(int v, int par, vector<vector<int> > &G, vector<bool> &good,
         vector<int> &ansDown, vector<int> &sub, vector<int> &goodInSub,
         vector<int> &p) {
  p[v] = par;
  int sumGoodSubs = 0;
  for (int u : G[v])
    if (u != par) {
      dfs(u, v, G, good, ansDown, sub, goodInSub, p);
      goodInSub[v] += goodInSub[u];
      sub[v] += sub[u];
      if (goodInSub[u] == sub[u]) {
        sumGoodSubs += sub[u];
      }
    }
  if (good[v]) {
    for (int u : G[v])
      if (u != par) {
        int restGoodSubs = sumGoodSubs - (goodInSub[u] == sub[u]) * sub[u];
        ansDown[v] = max(ansDown[v], ansDown[u] + 1 + restGoodSubs);
      }
  }
}
int solve(vector<vector<int> > &G, vector<bool> &good) {
  int n = (int)(G).size();
  vector<int> ansDown(n), sub(n, 1), par(n), goodInSub(n);
  for (int i = (0); i <= (n - 1); ++i) ansDown[i] = goodInSub[i] = good[i];
  dfs(0, -1, G, good, ansDown, sub, goodInSub, par);
  int allGood = 0;
  for (int i = (0); i <= (n - 1); ++i) allGood += good[i];
  vector<int> up(n);
  for (int i = (0); i <= (n - 1); ++i) {
    int upGood = allGood - goodInSub[i];
    if (upGood == n - sub[i]) {
      up[i] = upGood;
    } else {
      up[i] = 0;
    }
  }
  int ans = 0;
  for (int i = (0); i <= (n - 1); ++i) ans = max(ans, ansDown[i] + up[i]);
  for (int v = (0); v <= (n - 1); ++v)
    if (good[v]) {
      int sumGoodSubs = 0;
      for (int u : G[v])
        if (u != par[v] && (goodInSub[u] == sub[u])) {
          sumGoodSubs += sub[u];
        }
      int bestSoFar = 0;
      for (int u : G[v])
        if (u != par[v]) {
          int change = ansDown[u] - (goodInSub[u] == sub[u]) * sub[u];
          ans = max(ans, up[v] + 1 + bestSoFar + change);
          bestSoFar = max(bestSoFar, sumGoodSubs + change);
        }
    }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  int n, k;
  cin >> n >> k;
  vector<int> T(n);
  for (int i = (0); i <= (n - 1); ++i) cin >> T[i];
  vector<vector<int> > G(n);
  for (int i = (1); i <= (n - 1); ++i) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  const int MAXA = 1000002;
  int L = 0, R = MAXA;
  while (R - L > 1) {
    int mid = (L + R) / 2;
    vector<bool> good(n);
    for (int i = (0); i <= (n - 1); ++i) good[i] = (T[i] >= mid);
    if (solve(G, good) >= k)
      L = mid;
    else
      R = mid;
  }
  cout << L;
  return 0;
}
