#include <bits/stdc++.h>
using namespace std;
const int N = 200 * 1000 + 100;
vector<int> Graf[N];
int T[N];
int Syn[N];
int MD[N];
int MG[N];
void Wczytaj(int n, int k) {
  int i, v, u;
  for (i = 1; i <= n; i++) scanf("%d", &T[i]);
  for (i = 0; i < n - 1; i++) {
    scanf("%d%d", &v, &u);
    Graf[v].push_back(u);
    Graf[u].push_back(v);
  }
}
void DFSIn(int v, int ojciec, int s) {
  int i;
  int ile, reszta;
  Syn[v] = 1;
  ile = reszta = 0;
  for (i = 0; i < Graf[v].size(); i++) {
    if (Graf[v][i] != ojciec) {
      DFSIn(Graf[v][i], v, s);
      Syn[v] += Syn[Graf[v][i]];
      if (MD[Graf[v][i]] == Syn[Graf[v][i]])
        ile += Syn[Graf[v][i]];
      else
        reszta = max(reszta, MD[Graf[v][i]]);
    }
  }
  if (T[v] >= s) {
    MD[v] = ile + reszta + 1;
  } else
    MD[v] = 0;
}
void DFSG(int v, int ojciec, int s, int z_gory, int n) {
  if (Graf[v].size() == 1 && v != ojciec) {
    if (T[v] >= s) MG[v] = 1 + z_gory;
    return;
  }
  int i;
  int p, d, aktu;
  p = d = -1;
  for (i = 0; i < Graf[v].size(); i++)
    if (Graf[v][i] != ojciec && MD[Graf[v][i]] != Syn[Graf[v][i]])
      p = d = Graf[v][i];
  for (i = 0; i < Graf[v].size(); i++) {
    if (Graf[v][i] != ojciec && MD[Graf[v][i]] != Syn[Graf[v][i]]) {
      if (MD[Graf[v][i]] > MD[p]) {
        d = p;
        p = Graf[v][i];
      } else {
        if (MD[Graf[v][i]] >= MD[d]) d = Graf[v][i];
      }
    }
  }
  if (T[v] >= s) {
    if (z_gory == n - Syn[v])
      MG[v] = MD[v] + z_gory;
    else {
      if (z_gory > MD[p])
        MG[v] = MD[v] - MD[p] + z_gory;
      else {
        if (MD[p] == 0)
          MG[v] = MD[v] + z_gory;
        else
          MG[v] = MD[v];
      }
    }
  }
  for (i = 0; i < Graf[v].size(); i++) {
    if (Graf[v][i] != ojciec) {
      if (T[v] >= s) {
        aktu = MG[v];
        if (MD[Graf[v][i]] == Syn[Graf[v][i]])
          DFSG(Graf[v][i], v, s, aktu - Syn[Graf[v][i]], n);
        else {
          if (z_gory == n - Syn[v]) {
            if (p == d && Graf[v][i] == p)
              DFSG(Graf[v][i], v, s, aktu - MD[p], n);
            else {
              if (Graf[v][i] == p)
                DFSG(Graf[v][i], v, s, aktu - MD[p] + MD[d], n);
              else
                DFSG(Graf[v][i], v, s, aktu, n);
            }
          } else {
            if (z_gory >= MD[p])
              DFSG(Graf[v][i], v, s, aktu, n);
            else {
              if (p == d && Graf[v][i] == p) {
                DFSG(Graf[v][i], v, s, aktu - MD[p] + z_gory, n);
              } else {
                if (p == Graf[v][i])
                  DFSG(Graf[v][i], v, s, aktu - MD[p] + max(z_gory, MD[d]), n);
                else
                  DFSG(Graf[v][i], v, s, aktu, n);
              }
            }
          }
        }
      } else {
        DFSG(Graf[v][i], v, s, 0, n);
      }
    }
  }
}
bool Sprawdz(int n, int s, int l) {
  int i;
  for (i = 1; i <= n; i++) MD[i] = MG[i] = 0;
  DFSIn(1, 1, s);
  DFSG(1, 1, s, 0, n);
  for (i = 1; i <= n; i++) {
    if (MG[i] >= l) return true;
  }
  return false;
}
int Wyszukaj(int p, int k, int l, int n) {
  int s;
  while (p < k) {
    s = (p + k + 1) / 2;
    if (Sprawdz(n, s, l))
      p = s;
    else
      k = s - 1;
  }
  return p;
}
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  Wczytaj(n, k);
  printf("%d\n", Wyszukaj(0, 1000 * 1000 + 10, k, n));
  return 0;
}
