#include <bits/stdc++.h>
using namespace std;
int n, need;
int limit;
vector<int> e[200001];
bool visited[200001];
int w[200001];
int dp[200001];
bool haveBad[200001];
int bestVal;
void dfs(int cur, int from) {
  int maxForBad = 0;
  visited[cur] = true;
  haveBad[cur] = false;
  dp[cur] = 1;
  for (int i = 0; i < e[cur].size(); i++) {
    int t = e[cur][i];
    if (t == from) continue;
    if (w[t] < limit)
      haveBad[cur] = true;
    else {
      dfs(t, cur);
      if (haveBad[t]) {
        haveBad[cur] = true;
        maxForBad = max(maxForBad, dp[t]);
      } else
        dp[cur] += dp[t];
    }
  }
  dp[cur] += maxForBad;
  bestVal = max(bestVal, dp[cur]);
}
void dfs2(int cur, int from, bool isBad, int val) {
  int nowDP = 1;
  int maxForBad = 0;
  int maxForBadSecond = 0;
  int maxForBadWhich = -1;
  int haveBadElsewhere = isBad;
  int cntBadSon = 0;
  if (isBad)
    maxForBad = val;
  else
    nowDP += val;
  for (int i = 0; i < e[cur].size(); i++) {
    int t = e[cur][i];
    if (t == from) continue;
    if (w[t] < limit) {
      haveBadElsewhere = true;
      continue;
    }
    if (haveBad[t]) {
      if (dp[t] > maxForBad) {
        maxForBadSecond = maxForBad;
        maxForBad = dp[t];
        maxForBadWhich = i;
      } else if (dp[t] > maxForBadSecond) {
        maxForBadSecond = dp[t];
      }
      cntBadSon++;
    } else
      nowDP += dp[t];
  }
  for (int i = 0; i < e[cur].size(); i++) {
    int t = e[cur][i];
    if (t == from) continue;
    if (w[t] < limit) {
      continue;
    }
    bool isBadNext = true;
    if (haveBadElsewhere == 0 &&
        (cntBadSon == 0 || (cntBadSon == 1 && haveBad[t])))
      isBadNext = false;
    int maxBadNext = maxForBad;
    if (i == maxForBadWhich) maxBadNext = maxForBadSecond;
    dfs2(t, cur, isBadNext, nowDP + maxBadNext - (haveBad[t] ? 0 : dp[t]));
  }
  bestVal = max(bestVal, nowDP + maxForBad);
}
bool check() {
  memset(visited, false, sizeof(visited));
  for (int i = 1; i <= n; i++)
    if (w[i] >= limit)
      if (!visited[i]) {
        bestVal = 0;
        dfs(i, -1);
        dfs2(i, -1, 0, 0);
        if (bestVal >= need) return true;
      }
  return false;
}
int MAIN() {
  cin >> n >> need;
  for (int i = 1; i <= n; i++) cin >> w[i];
  for (int i = 1; i < n; i++) {
    int a, b;
    cin >> a >> b;
    e[a].push_back(b);
    e[b].push_back(a);
  }
  int L = 0, R = 1000000, M;
  while (R - L > 1) {
    M = (L + R) / 2;
    limit = M;
    if (check())
      L = M;
    else
      R = M;
  }
  cout << L << endl;
  return 0;
}
int main() {
  int start = clock();
  ios ::sync_with_stdio(false);
  cout << fixed << setprecision(16);
  int ret = MAIN();
  return ret;
}
