#include <bits/stdc++.h>
using namespace std;
bool w, B[(int)(2e5 + 10)];
int i, j, k, n, m, x, y, z, A[(int)(2e5 + 10)], C[(int)(2e5 + 10)],
    a[(int)(2e5 + 10)], ort, mx[(int)(2e5 + 10)], mx2[(int)(2e5 + 10)];
vector<int> arr[(int)(2e5 + 10)];
void f2(int x, int root, int t, int t2) {
  int p = 1, mx = 0;
  if (a[x] >= ort) {
    for (int i = 0; i < arr[x].size(); i++) {
      if (arr[x][i] != root) {
        if (C[arr[x][i]] == A[arr[x][i]])
          p += C[arr[x][i]];
        else
          mx = max(mx, A[arr[x][i]] + ::mx[arr[x][i]]);
      } else {
        if (C[1] - C[x] == t)
          p += t;
        else
          mx = max(mx, t + t2);
      }
    }
    if (p + mx >= k) {
      w = 1;
    }
  }
  for (int i = 0; i < arr[x].size(); i++) {
    if (arr[x][i] != root) {
      if (a[x] >= ort) {
        if (A[x] - A[arr[x][i]] + t == C[1] - C[arr[x][i]])
          f2(arr[x][i], x, A[x] - A[arr[x][i]] + t, 0);
        else {
          int p = ::mx[x];
          if (p == A[arr[x][i]] + ::mx[arr[x][i]] and
              A[arr[x][i]] != C[arr[x][i]])
            p = mx2[x];
          if (t == C[1] - C[x]) {
            if (A[arr[x][i]] == C[arr[x][i]])
              f2(arr[x][i], x, A[x] - A[arr[x][i]] + t, p);
            else
              f2(arr[x][i], x, A[x] + t, p);
          } else {
            if (A[arr[x][i]] == C[arr[x][i]])
              f2(arr[x][i], x, A[x] - A[arr[x][i]], max(p, t + t2));
            else
              f2(arr[x][i], x, A[x], max(p, t + t2));
          }
        }
      } else
        f2(arr[x][i], x, 0, 0);
    }
  }
}
void f(int x, int root) {
  C[x] = 1;
  A[x] = 0;
  mx[x] = mx2[x] = 0;
  for (int i = 0; i < arr[x].size(); i++)
    if (arr[x][i] != root) {
      f(arr[x][i], x);
      int p = A[arr[x][i]] + mx[arr[x][i]];
      if (A[arr[x][i]] == C[arr[x][i]])
        A[x] += A[arr[x][i]];
      else if (mx[x] < p) {
        mx2[x] = mx[x];
        mx[x] = p;
      } else
        mx2[x] = max(mx2[x], p);
      C[x] += C[arr[x][i]];
    }
  if (a[x] < ort)
    mx[x] = mx2[x] = A[x] = 0;
  else
    A[x]++;
}
int main() {
  cin >> n >> k;
  for (i = 1; i <= n; i++) scanf("%d", a + i);
  for (i = 1; i < n; i++) {
    scanf("%d %d", &x, &y);
    arr[x].push_back(y);
    arr[y].push_back(x);
  }
  int bas = 1;
  int son = (int)(2e5 + 10) * 10;
  while (bas < son) {
    ort = bas + son >> 1;
    if (bas == ort) ort++;
    w = 0;
    f(1, 0);
    f2(1, 0, 0, 0);
    if (w)
      bas = ort;
    else
      son = ort - 1;
  }
  cout << bas << '\n';
}
