#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 2, inf = 1e9 + 7;
char O[1 << 14], *S = O, *T = O;
inline int read() {
  int x = 0, f = 1;
  char ch =
      (S == T && (T = (S = O) + fread(O, 1, 1 << 14, stdin), S == T) ? -1
                                                                     : *S++);
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = (S == T && (T = (S = O) + fread(O, 1, 1 << 14, stdin), S == T) ? -1
                                                                        : *S++);
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 1) + (x << 3) + (ch ^ 48);
    ch = (S == T && (T = (S = O) + fread(O, 1, 1 << 14, stdin), S == T) ? -1
                                                                        : *S++);
  }
  return x * f;
}
struct E {
  int y, nex;
} e[N << 1];
int len, fir[N];
void ins(int x, int y) { e[++len] = (E){y, fir[x]}, fir[x] = len; }
int a[N], m, sz[N], f[N], K;
bool ok;
void dfs(int x, int fa) {
  sz[x] = 1;
  f[x] = (a[x] >= m);
  int mx = 0, x2 = 0;
  for (int k = fir[x]; k; k = e[k].nex) {
    int y = e[k].y;
    if (y == fa) continue;
    dfs(y, x);
    sz[x] += sz[y];
    if (f[x] && f[y] == sz[y])
      f[x] += f[y];
    else if (f[y] > mx)
      x2 = mx, mx = f[y];
    else if (f[y] > x2)
      x2 = f[y];
  }
  if (f[x]) f[x] += mx;
  if (f[x] && f[x] + x2 >= K) ok = 1;
}
int main() {
  int i, n = read(), l = 1, r = 0;
  K = read();
  for (i = 1; i <= n; ++i) a[i] = read(), r = a[i] > r ? a[i] : r;
  for (i = 1; i < n; ++i) {
    int x = read(), y = read();
    ins(x, y), ins(y, x);
  }
  int x = 1;
  for (i = 2; i <= n; ++i)
    if (a[i] < a[x]) x = i;
  int ans;
  while (l <= r) {
    m = l + r >> 1;
    ok = 0;
    dfs(x, 0);
    if (ok)
      l = (ans = m) + 1;
    else
      r = m - 1;
  }
  printf("%d\n", ans);
  return 0;
}
