#include <bits/stdc++.h>
using namespace std;
const int C = 200001;
vector<vector<int> > tr(C);
int ij[C], a, b, n, m;
int s[C], is = 0, son[C], par[C], ji[C], dead[C], v[C], fll[C], best[2][C],
          ab[C];
int proc_tree(int a, int n, vector<vector<int> > &tab, int ij[]) {
  s[0] = a, is = 1;
  int b, k, mx = 0, z;
  for (z = 1; z <= n; z++)
    son[z] = 0, ji[z] = ij[z], par[z] = 0, best[0][z] = best[1][z] = ab[z] = 0,
    fll[z] = 0;
  while (is > 0) {
    a = s[is - 1];
    if (ji[a] > 0 && tab[a][ji[a] - 1] == par[a]) ji[a]--;
    if (ji[a] > 0)
      b = s[is] = tab[a][ji[a] - 1], par[b] = a, is++, ji[a]--;
    else {
      b = par[a];
      fll[a] = ((dead[a] == 1) ? 0 : (fll[a] + 1));
      son[a]++, son[b] += son[a], is--;
      if (dead[a] == 1) continue;
      if (fll[a] == son[a])
        fll[b] += fll[a];
      else {
        if (fll[a] + best[0][a] > best[0][b])
          best[1][b] = best[0][b], best[0][b] = fll[a] + best[0][a], ab[b] = a;
        else if (fll[a] + best[0][a] > best[1][b])
          best[1][b] = fll[a] + best[0][a];
      }
    }
  }
  for (z = 1; z <= n; z++) ji[z] = ij[z];
  is = 1;
  while (is > 0) {
    a = s[is - 1];
    if (ji[a] > 0 && tab[a][ji[a] - 1] == par[a]) ji[a]--;
    if (ji[a] > 0) {
      b = s[is] = tab[a][ji[a] - 1], is++, ji[a]--;
      if (dead[a] == 1 || dead[b] == 1) continue;
      if (fll[b] == son[b])
        k = fll[a] - fll[b];
      else if (ab[a] == b)
        k = fll[a] + best[1][a];
      else
        k = fll[a] + best[0][a];
      if (k == n - son[b])
        fll[b] += k;
      else if (k > best[0][b])
        best[1][b] = best[0][b], best[0][b] = k, ab[b] = a;
      else if (k > best[1][b])
        best[1][b] = k;
    } else
      is--;
  }
  for (z = 1; z <= n; z++)
    if (fll[z] + best[0][z] > mx) mx = fll[z] + best[0][z];
  return mx;
}
int main() {
  int l = 0, r = 1000001, i, k;
  scanf("%d %d", &n, &k);
  for (i = 1; i <= n; i++) scanf("%d", &v[i]);
  for (int z = 1; z < n; z++)
    scanf("%d %d", &a, &b), tr[a].push_back(b), tr[b].push_back(a), ij[a]++,
        ij[b]++;
  while (l <= r) {
    m = (l + r) / 2;
    for (i = 1; i <= n; i++) dead[i] = ((v[i] > m) ? 0 : 1);
    if (proc_tree(1, n, tr, ij) < k)
      r = m - 1;
    else
      l = m + 1;
  }
  printf("%d\n", l);
  return 0;
}
