#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 7;
int n, k, i, x, y, bas, son, ort, bound, r;
int A[N], B[N], size[N], mx[N], mx2[N];
vector<int> V[N];
void dfs(int x, int ata = 0) {
  size[x] = 1;
  for (int i = 0; i < V[x].size(); i++)
    if (V[x][i] != ata) {
      dfs(V[x][i], x);
      size[x] += size[V[x][i]];
      if (B[V[x][i]] == size[V[x][i]])
        B[x] += B[V[x][i]];
      else {
        if (B[V[x][i]] > mx[x]) {
          mx2[x] = mx[x];
          mx[x] = B[V[x][i]];
        } else
          mx2[x] = max(mx2[x], B[V[x][i]]);
      }
    }
  B[x] += mx[x];
  if (A[x] >= bound)
    B[x]++;
  else {
    B[x] = 0;
    mx[x] = 0;
    mx2[x] = 0;
  }
}
void dfs2(int x, int ata = 0) {
  int oldx, oldvx, oldmx, oldmx2;
  r |= (B[x] >= k);
  for (int i = 0; i < V[x].size(); i++)
    if (V[x][i] != ata) {
      if (!B[x] or !B[V[x][i]]) {
        dfs2(V[x][i], x);
        continue;
      }
      oldx = B[x];
      oldvx = B[V[x][i]];
      oldmx = mx[V[x][i]];
      oldmx2 = mx2[V[x][i]];
      if (size[V[x][i]] == B[V[x][i]])
        B[x] -= B[V[x][i]];
      else if (mx[x] == B[V[x][i]]) {
        B[x] -= mx[x];
        B[x] += mx2[x];
      }
      if (B[x] == size[1] - size[V[x][i]])
        B[V[x][i]] += B[x];
      else if (B[x] > mx[V[x][i]]) {
        B[V[x][i]] -= mx[V[x][i]];
        B[V[x][i]] += B[x];
        mx2[V[x][i]] = mx[V[x][i]];
        mx[V[x][i]] = B[x];
      } else if (B[x] > mx2[V[x][i]])
        mx2[V[x][i]] = B[x];
      dfs2(V[x][i], x);
      B[x] = oldx;
      B[V[x][i]] = oldvx;
      mx[V[x][i]] = oldmx;
      mx2[V[x][i]] = oldmx2;
    }
}
bool ok(int x) {
  bound = x;
  memset(B, 0, sizeof B);
  memset(size, 0, sizeof size);
  memset(mx, 0, sizeof mx);
  memset(mx2, 0, sizeof mx2);
  r = 0;
  dfs(1);
  dfs2(1);
  return r;
}
int main() {
  scanf("%d %d", &n, &k);
  for (i = 1; i <= n; i++) scanf("%d", A + i);
  for (i = 1; i < n; i++) {
    scanf("%d %d", &x, &y);
    V[x].push_back(y);
    V[y].push_back(x);
  }
  bas = 1;
  son = 1e6;
  while (bas < son) {
    ort = bas + son >> 1;
    if (bas == ort) ort++;
    if (ok(ort))
      bas = ort;
    else
      son = ort - 1;
  }
  printf("%d", bas);
}
