#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void next_int(T &x) {
  x = 0;
  char c;
  bool neg = false;
  while (!isdigit(c = getchar()))
    if (c == '-') neg = true;
  do x = x * 10 + c - 48;
  while (isdigit(c = getchar()));
  if (neg) x = -x;
}
template <typename T>
inline void write_int(T x, char last = 0) {
  if (x < 0) putchar('-'), x = abs(x);
  char tmp[20];
  int cnt = 0;
  while (x >= 10) tmp[cnt++] = x % 10 + 48, x /= 10;
  tmp[cnt] = x + 48;
  for (int i = (cnt); i >= (0); --i) putchar(tmp[i]);
  if (last) putchar(last);
}
const int N = (int)2e5 + 5;
int n, k, dp[N], a[N], sz[N], maxp[N];
vector<int> g[N];
void dfs_prep(int u, int p, const int &mid) {
  sz[u] = 1, maxp[u] = 0;
  int maxsub = 0;
  for (auto v : g[u])
    if (v != p) {
      dfs_prep(v, u, mid);
      sz[u] += sz[v];
      if (maxp[v] == sz[v])
        maxp[u] += maxp[v];
      else
        maxsub = max(maxsub, maxp[v]);
    }
  if (a[u] >= mid)
    maxp[u] += maxsub + 1;
  else
    maxp[u] = 0;
}
void dfs_res(int u, int p, int &res, const int &mid) {
  int max1 = 0, max2 = 0, cnt = 0;
  for (auto v : g[u]) {
    if ((v == p && dp[u] == n - sz[u]) || (v != p && maxp[v] == sz[v])) {
      cnt += (v == p ? dp[u] : maxp[v]);
      continue;
    }
    int val = v == p ? dp[u] : maxp[v];
    if (max1 == 0 || (max1 == p ? dp[u] : maxp[max1]) < val)
      max2 = max1, max1 = v;
    else if (max2 == 0 || (max2 == p ? dp[u] : maxp[max2]) < val)
      max2 = v;
  }
  for (auto v : g[u])
    if (v != p) {
      if (a[u] >= mid) {
        if (sz[v] == maxp[v])
          dp[v] = cnt - maxp[v] + (max1 == p ? dp[u] : maxp[max1]) + 1;
        else {
          if (max1 == v)
            dp[v] = cnt + (max2 == p ? dp[u] : maxp[max2]) + 1;
          else
            dp[v] = cnt + (max1 == p ? dp[u] : maxp[max1]) + 1;
        }
      } else
        dp[v] = 0;
      dfs_res(v, u, res, mid);
    }
  if (a[u] >= mid) res = max(res, cnt + (max1 == p ? dp[u] : maxp[max1]) + 1);
}
bool check(int mid) {
  int res = 0;
  dfs_prep(1, 0, mid);
  dfs_res(1, 0, res, mid);
  return res >= k;
}
int main() {
  next_int(n), next_int(k);
  for (int i = (1); i <= (n); ++i) next_int(a[i]);
  for (int i = (1); i < (n); ++i) {
    int u, v;
    next_int(u), next_int(v);
    g[u].push_back(v);
    g[v].push_back(u);
  }
  int lo = 1, hi = (int)1e6, ans = 1, mid;
  while (lo <= hi) {
    mid = (lo + hi) >> 1;
    if (check(mid))
      ans = mid, lo = mid + 1;
    else
      hi = mid - 1;
  }
  write_int(ans);
  return 0;
}
