#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int n, m, lim, p = 1, a[N], nex[N * 2], spot[N * 2], head[N], fa[N], f[N], g[N];
int maxcolor[N][2], c[N];
bool color[N], v[N];
void add(int x, int y) {
  nex[++p] = head[x], head[x] = p, spot[p] = y;
  nex[++p] = head[y], head[y] = p, spot[p] = x;
}
void dfs1(int x) {
  int tp, y, cnt = 0, m1 = 0, m2 = 0;
  v[x] = 1;
  for (tp = head[x]; y = spot[tp], tp; tp = nex[tp])
    if (a[y] >= lim && y != fa[x]) {
      fa[y] = x;
      dfs1(y);
      if (!c[y])
        cnt += f[y];
      else {
        c[x]++;
        if (f[y] > m2) m2 = f[y];
        if (m1 < m2) swap(m1, m2);
      }
    }
  maxcolor[x][0] = m1;
  maxcolor[x][1] = m2;
  f[x] = cnt + m1 + 1;
  c[x] += color[x];
}
void dfs2(int x, int &ret) {
  if (fa[x]) {
    if (c[fa[x]] - (c[x] != 0) > 0) {
      if (c[x]) {
        if (f[x] < maxcolor[fa[x]][0]) {
          g[x] = f[x] - maxcolor[x][0] + max(maxcolor[x][0], g[fa[x]]);
          if (g[fa[x]] > maxcolor[x][1]) maxcolor[x][1] = g[fa[x]];
          if (maxcolor[x][0] < maxcolor[x][1])
            swap(maxcolor[x][0], maxcolor[x][1]);
        } else {
          g[x] = f[x] - maxcolor[x][0] +
                 max(maxcolor[x][0],
                     g[fa[x]] - maxcolor[fa[x]][0] + maxcolor[fa[x]][1]);
          if (g[fa[x]] - maxcolor[fa[x]][0] + maxcolor[fa[x]][1] >
              maxcolor[x][1])
            maxcolor[x][1] = g[fa[x]] - maxcolor[fa[x]][0] + maxcolor[fa[x]][1];
          if (maxcolor[x][0] < maxcolor[x][1])
            swap(maxcolor[x][0], maxcolor[x][1]);
        }
      } else
        g[x] = f[x] - maxcolor[x][0] + max(maxcolor[x][0], g[fa[x]] - f[x]);
    } else {
      if (c[x]) {
        if (f[x] < maxcolor[fa[x]][0])
          g[x] = f[x] + g[fa[x]];
        else
          g[x] = f[x] + g[fa[x]] - maxcolor[fa[x]][0] + maxcolor[fa[x]][1];
      } else
        g[x] = g[fa[x]];
    }
    c[x] += ((c[fa[x]] - (c[x] != 0)) != 0);
  } else
    g[x] = f[x];
  ret = max(ret, g[x]);
  for (int tp = head[x]; tp; tp = nex[tp])
    if (a[spot[tp]] >= lim && spot[tp] != fa[x]) dfs2(spot[tp], ret);
}
int solve() {
  memset(v, 0, sizeof(v));
  memset(fa, 0, sizeof(fa));
  memset(c, 0, sizeof(c));
  int maxn = 0;
  for (int i = 1; i <= n; i++)
    if (a[i] >= lim && v[i] == 0) {
      dfs1(i), dfs2(i, maxn);
    }
  return maxn >= m;
}
int main() {
  int i, x, y, l, r, tp;
  cin >> n >> m;
  for (i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (i = 1; i < n; i++) {
    scanf("%d%d", &x, &y);
    add(x, y);
  }
  for (l = 1, r = 1000000; l < r;) {
    lim = l + r + 1 >> 1;
    memset(color, 0, sizeof(color));
    for (i = 1; i <= n; i++)
      if (a[i] < lim)
        for (tp = head[i]; tp; tp = nex[tp]) color[spot[tp]] = 1;
    if (solve())
      l = lim;
    else
      r = lim - 1;
  }
  cout << l;
  return 0;
}
