#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 2e5 + 10;
int n, k;
int Arr[MAX_N];
int len[MAX_N];
int dp[MAX_N];
int tmp[MAX_N][2];
bool ok[MAX_N];
vector<int> G[MAX_N];
void dfsDown(int v = 0, int p = 0) {
  dp[v] = ok[v];
  tmp[v][0] = tmp[v][1] = 0;
  len[v] = 1;
  for (int u : G[v])
    if (u != p) {
      dfsDown(u, v);
      len[v] += len[u];
      if (dp[u] + tmp[u][0] == len[u])
        dp[v] += dp[u] + tmp[u][0];
      else {
        if (tmp[v][0] <= dp[u] + tmp[u][0]) {
          tmp[v][1] = tmp[v][0];
          tmp[v][0] = dp[u] + tmp[u][0];
        } else
          tmp[v][1] = max(tmp[v][1], dp[u] + tmp[u][0]);
      }
    }
  dp[v] *= ok[v];
  tmp[v][0] *= ok[v];
  tmp[v][1] *= ok[v];
}
bool dfsUp(int v = 0, int p = 0, int val = 0) {
  val *= ok[v];
  if (n - len[v] == val)
    dp[v] += val;
  else {
    if (tmp[v][0] <= val) {
      tmp[v][1] = tmp[v][0];
      tmp[v][0] = val;
    } else
      tmp[v][1] = max(tmp[v][1], val);
  }
  if (k <= dp[v] + tmp[v][0]) return true;
  for (int u : G[v])
    if (u != p) {
      if (dp[u] + tmp[u][0] == len[u]) {
        if (dfsUp(u, v, ok[v] * (dp[v] - dp[u] - tmp[u][0] + tmp[v][0])))
          return true;
      } else {
        if (dp[u] + tmp[u][0] == tmp[v][0]) {
          if (dfsUp(u, v, ok[v] * (dp[v] + tmp[v][1]))) return true;
        } else {
          if (dfsUp(u, v, ok[v] * (dp[v] + tmp[v][0]))) return true;
        }
      }
    }
  return false;
}
bool can(int d) {
  for (int i = 0; i < n; i++) ok[i] = (d <= Arr[i]);
  dfsDown();
  return dfsUp();
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> Arr[i];
  for (int i = 0; i < n - 1; i++) {
    int v, u;
    cin >> v >> u;
    v--, u--;
    G[v].push_back(u);
    G[u].push_back(v);
  }
  int s = 0, e = 1000001;
  while (e - s > 1) {
    int med = e + s >> 1;
    if (can(med))
      s = med;
    else
      e = med;
  }
  cout << s << "\n";
  return 0;
}
