#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + (ch ^ 48);
    ch = getchar();
  }
  return x * f;
}
const int N = 200010, INF = 0x3f3f3f3f;
struct edge {
  int v, nxt;
} e[N << 1];
int head[N], cnt, n, k, x, y, a[N], f[N], siz[N], g, ans;
inline int cmin(int x, int y) { return a[x] < a[y] ? x : y; }
inline void add(int u, int v) {
  e[++cnt].v = v;
  e[cnt].nxt = head[u];
  head[u] = cnt;
}
inline void dfs(int u, int fa, int k) {
  f[u] = siz[u] = 1;
  int maxx = 0, cmax = 0;
  for (int i = head[u]; i; i = e[i].nxt) {
    int v = e[i].v;
    if (v == fa) continue;
    dfs(v, u, k);
    siz[u] += siz[v];
    if (f[v] == siz[v])
      f[u] += siz[v];
    else {
      if (maxx < f[v])
        cmax = maxx, maxx = f[v];
      else
        cmax = max(cmax, f[v]);
    }
  }
  f[u] = (a[u] < k) ? 0 : f[u] + maxx;
  ans = max(ans, f[u] + cmax);
}
inline bool check(int x) {
  ans = 0;
  dfs(g, 0, x);
  return ans >= k;
}
inline void mian() {
  n = read();
  k = read();
  int l, r;
  a[0] = l = INF;
  r = 0;
  for (int i = 1; i <= n; ++i)
    a[i] = read(), g = cmin(g, i), l = min(l, a[i]), r = max(r, a[i]);
  ++r;
  for (int i = 1; i <= n - 1; ++i) {
    x = read();
    y = read();
    add(x, y);
    add(y, x);
  }
  while (l < r) {
    int mid = l + r >> 1;
    if (check(mid))
      l = mid + 1;
    else
      r = mid;
  }
  printf("%d\n", r - 1);
}
int main() {
  int qwq = 1;
  while (qwq--) mian();
  return 0;
}
