#include <bits/stdc++.h>
using namespace std;
inline long long in() {
  int32_t x;
  scanf("%d", &x);
  return x;
}
inline string getStr() {
  char ch[500001];
  scanf("%s", ch);
  return ch;
}
const long long MAX_N = 2e5 + 10;
inline long long gcd(long long a, long long b) {
  return b == 0 ? a : gcd(b, a % b);
}
vector<long long> g[MAX_N];
bool del[MAX_N], forb[MAX_N], mark[MAX_N];
long long a[MAX_N], dp[MAX_N], ln, vl[MAX_N], deg[MAX_N];
queue<long long> Bomb;
long long n, k;
inline void BombProcess() {
  for (long long i = 1; i <= n; i++)
    if (deg[i] == 1 && !forb[i]) Bomb.push(i);
  while (Bomb.size()) {
    long long first = Bomb.front();
    Bomb.pop();
    deg[first]--;
    del[first] = true;
    long long FIND = -1;
    for (auto u : g[first]) {
      if (!del[u] && !forb[u]) {
        FIND = u;
        break;
      }
    }
    if (FIND != -1) {
      vl[FIND] += vl[first];
      deg[FIND]--;
      if (deg[FIND] == 1) Bomb.push(FIND);
    }
    ln = max(ln, vl[first]);
    vl[first] = 0;
  }
}
inline void dfs(long long v, long long pr = -1) {
  mark[v] = true;
  long long f = 0, s = 0;
  dp[v] = vl[v];
  for (auto u : g[v]) {
    if (pr == u || forb[u]) continue;
    dfs(u, v);
    if (dp[u] > f) {
      s = f;
      f = dp[u];
    } else
      s = max(s, dp[u]);
  }
  ln = max(ln, dp[v] + f + s);
  dp[v] += f;
}
inline bool can(long long low) {
  ln = 0;
  for (long long i = 1; i <= n; i++) {
    mark[i] = 0;
    deg[i] = g[i].size();
    dp[i] = 0;
    del[i] = 0;
    mark[i] = 0;
    vl[i] = 1;
    forb[i] = (a[i] < low);
  }
  BombProcess();
  for (long long i = 1; i <= n; i++) {
    if (!mark[i] && !forb[i]) dfs(i, -1);
  }
  return ln >= k;
}
int32_t main() {
  n = in(), k = in();
  for (long long i = 0; i < n; i++) a[i + 1] = in();
  for (long long i = 0; i < n - 1; i++) {
    long long v = in(), u = in();
    g[v].push_back(u);
    g[u].push_back(v);
  }
  long long l = 0, r = (1 << 20), best = 0, mid;
  while (l <= r) {
    mid = (l + r) >> 1;
    if (can(mid)) {
      best = mid;
      l = mid + 1;
      continue;
    }
    r = mid - 1;
  }
  cout << best << "\n";
}
