#include <bits/stdc++.h>
using namespace std;
vector<int> e[200010];
int f[200010][2], suml[200010], sumr[200010], ml[200010], mr[200010];
int n, m, ans, b[200010], a[200010], F0[200010], F1[200010], sz[200010];
inline int Read() {
  char c = getchar();
  int num = 0;
  while ('0' > c || c > '9') c = getchar();
  while ('0' <= c && c <= '9') num = num * 10 + c - '0', c = getchar();
  return (num);
}
inline int Dfs(int x, int y) {
  sz[x] = 1;
  for (int i = 0; i < e[x].size(); i++)
    if (e[x][i] != y) sz[x] += Dfs(e[x][i], x);
  return (sz[x]);
}
inline void Dfs1(int x, int y) {
  bool pd = 0;
  for (int i = 0; i < e[x].size(); i++)
    if (e[x][i] != y) Dfs1(e[x][i], x), f[x][1] += f[e[x][i]][1];
  if (!b[x]) {
    f[x][0] = f[x][1] = 0;
    return;
  }
  for (int i = 0; i < e[x].size(); i++)
    if (e[x][i] != y)
      f[x][0] = max(f[x][0], f[x][1] - f[e[x][i]][1] + f[e[x][i]][0]);
  f[x][1]++;
  if (f[x][1] != sz[x]) f[x][1] = 0;
  f[x][0]++;
}
inline bool Dfs2(int x, int y, int f0, int f1) {
  bool pd = 0;
  if (f0 + f[x][1] >= m || f1 + f[x][0] >= m) return (1);
  if (!b[x]) {
    for (int i = 0; i < e[x].size(); i++)
      if (e[x][i] != y) pd |= Dfs2(e[x][i], x, 0, 0);
    return (pd);
  }
  ml[0] = mr[e[x].size() + 1] = 0;
  suml[0] = sumr[e[x].size() + 1] = 0;
  for (int i = 0; i < e[x].size(); i++) {
    if (e[x][i] != y)
      suml[i + 1] = suml[i] + f[e[x][i]][1];
    else
      suml[i + 1] = suml[i];
    if (e[x][i] != y)
      ml[i + 1] = max(suml[i] + f[e[x][i]][0], ml[i] + f[e[x][i]][1]);
    else
      ml[i + 1] = ml[i];
  }
  for (int i = e[x].size() - 1; i >= 0; i--) {
    if (e[x][i] != y)
      sumr[i + 1] = sumr[i + 2] + f[e[x][i]][1];
    else
      sumr[i + 1] = sumr[i + 2];
    if (e[x][i] != y)
      mr[i + 1] = max(sumr[i + 2] + f[e[x][i]][0], mr[i + 2] + f[e[x][i]][1]);
    else
      mr[i + 1] = mr[i + 2];
  }
  for (int i = 0; i < e[x].size(); i++)
    if (e[x][i] != y) {
      F0[e[x][i]] = f0 + suml[i] + sumr[i + 2];
      F1[e[x][i]] = f1 + suml[i] + sumr[i + 2];
      F0[e[x][i]] = max(F0[e[x][i]], f1 + ml[i] + sumr[i + 2]);
      F0[e[x][i]] = max(F0[e[x][i]], f1 + mr[i + 2] + suml[i]);
      F0[e[x][i]]++;
      F1[e[x][i]]++;
      if (F1[e[x][i]] != n - sz[e[x][i]]) F1[e[x][i]] = 0;
    }
  for (int i = 0; i < e[x].size(); i++)
    if (e[x][i] != y) pd |= Dfs2(e[x][i], x, F0[e[x][i]], F1[e[x][i]]);
  return (pd);
}
inline bool Pd(int mid) {
  if (mid == 702646) int deb = 9;
  memset(f, 0, sizeof(f));
  memset(F0, 0, sizeof(F0));
  memset(F1, 0, sizeof(F1));
  memset(ml, 0, sizeof(ml));
  memset(mr, 0, sizeof(mr));
  for (int i = 1; i <= n; i++) b[i] = (a[i] >= mid);
  Dfs1(1, 0);
  return (Dfs2(1, 0, 0, 0));
}
int main() {
  n = Read();
  m = Read();
  int L = 1e9, R = 0;
  for (int i = 1; i <= n; i++)
    a[i] = Read(), L = min(L, a[i]), R = max(R, a[i]);
  for (int u, v, i = 1; i < n; i++)
    u = Read(), v = Read(), e[u].push_back(v), e[v].push_back(u);
  Dfs(1, 0);
  do {
    int mid = (L + R) / 2;
    if (Pd(mid))
      ans = mid, L = mid + 1;
    else
      R = mid - 1;
  } while (L <= R);
  printf("%d\n", ans);
}
