#include <bits/stdc++.h>
using namespace std;
long long n, tot, mp[2000006], h[2000006], m, ans, siz[2000006], dp[2000006],
    mi = 0x3f3f3f3f, rt, ma;
struct DX {
  long long v, p;
} dx[2000006];
void add(long long u, long long v) {
  dx[++tot].v = v;
  dx[tot].p = h[u];
  h[u] = tot;
}
void dfs(long long u, long long fx, long long mid) {
  siz[u] = 1;
  dp[u] = 1;
  long long ma1 = 0, ma2 = 0;
  for (long long i = h[u]; i; i = dx[i].p) {
    long long v = dx[i].v;
    if (v == fx) continue;
    dfs(v, u, mid);
    siz[u] += siz[v];
    if (siz[v] == dp[v])
      dp[u] += dp[v];
    else {
      if (dp[v] > ma1) swap(ma1, dp[v]);
      if (dp[v] > ma2) swap(ma2, dp[v]);
    }
  }
  dp[u] = mp[u] < mid ? 0 : dp[u] + ma1;
  ans = max(ans, dp[u] + ma2);
}
int main() {
  scanf("%lld%lld", &n, &m);
  for (long long i = 1; i <= n; i++) {
    scanf("%lld", &mp[i]);
    if (mp[i] < mi) {
      rt = i;
      mi = mp[i];
    }
    ma = max(ma, mp[i]);
  }
  long long a, b, l = mi, r = ma;
  for (long long i = 1; i < n; i++) {
    scanf("%lld%lld", &a, &b);
    add(a, b);
    add(b, a);
  }
  while (l <= r) {
    long long mid = (l + r) >> 1;
    ans = 0;
    dfs(rt, 0, mid);
    if (ans >= m)
      l = mid + 1;
    else
      r = mid - 1;
  }
  printf("%lld", l - 1);
  return 0;
}
