#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline bool upmin(T &x, T y) {
  return y < x ? x = y, 1 : 0;
}
template <typename T>
inline bool upmax(T &x, T y) {
  return x < y ? x = y, 1 : 0;
}
const long double eps = 1e-11;
const long double pi = acos(-1);
const long long oo = 1 << 30;
const long long loo = 1ll << 62;
const long long mods = 1e9 + 7;
const long long MAXN = 200005;
const long long INF = 0x3f3f3f3f;
inline long long read() {
  long long f = 1, x = 0;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = (x << 3) + (x << 1) + (c ^ 48);
    c = getchar();
  }
  return x * f;
}
vector<long long> e[MAXN];
long long num[MAXN], f[MAXN], c[MAXN], ans = 0;
void tree_dp(long long x, long long father, long long y) {
  num[x] = f[x] = 1;
  for (auto v : e[x])
    if (v != father) tree_dp(v, x, y);
  long long mx = 0, _mx = 0;
  for (auto v : e[x])
    if (v != father) {
      num[x] += num[v];
      if (num[v] == f[v])
        f[x] += f[v];
      else {
        if (f[v] > mx)
          _mx = mx, mx = f[v];
        else if (f[v] > _mx)
          _mx = f[v];
      }
    }
  f[x] += mx;
  if (c[x] < y)
    f[x] = 0, upmax(ans, mx);
  else
    upmax(ans, f[x] + _mx);
}
signed main() {
  long long n = read(), k = read(), mn = 1;
  for (long long i = 1; i <= n; i++)
    c[i] = read(), mn = (c[i] < c[mn] ? i : mn);
  for (long long i = 1, u, v; i < n; i++)
    u = read(), v = read(), e[u].push_back(v), e[v].push_back(u);
  long long l = c[mn], r = 1000000;
  while (l < r) {
    long long mid = (l + r + 1) >> 1;
    ans = 0, tree_dp(mn, 0, mid);
    if (ans >= k)
      l = mid;
    else
      r = mid - 1;
  }
  printf("%d\n", l);
  return 0;
}
