#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200000 + 5;
vector<int> G[MAXN];
int down[MAXN], up[MAXN], f[MAXN];
int siz[MAXN], cnt[MAXN], a[MAXN];
pair<int, int> son[MAXN][2];
int now, K, res;
void dfs1(int u, int p) {
  siz[u] = 1;
  cnt[u] = (a[u] >= now);
  for (int i = 0; i < G[u].size(); i++) {
    int v = G[u][i];
    if (v == p) continue;
    dfs1(v, u);
    siz[u] += siz[v];
    cnt[u] += cnt[v];
  }
}
void dfs2(int u, int p) {
  down[u] = 0;
  son[u][0] = son[u][1] = pair<int, int>(0, 0);
  for (int i = 0; i < G[u].size(); i++) {
    int v = G[u][i];
    if (v == p) continue;
    dfs2(v, u);
    if (cnt[v] == siz[v])
      down[u] += down[v];
    else if (down[v] > son[u][1].first) {
      if (down[v] > son[u][0].first) {
        son[u][1] = son[u][0];
        son[u][0] = pair<int, int>(down[v], v);
      } else
        son[u][1] = pair<int, int>(down[v], v);
    }
  }
  f[u] = down[u];
  if (a[u] < now)
    down[u] = 0;
  else
    down[u] += 1 + son[u][0].first;
}
void dfs3(int u, int p) {
  if (res) return;
  if (a[u] >= now) {
    int all = 0, mx = 0;
    if (cnt[1] - cnt[u] == siz[1] - siz[u])
      all += up[u];
    else
      mx = max(mx, up[u]);
    int tmp = down[u] - son[u][0].first;
    mx = max(mx, son[u][0].first);
    all += tmp + mx;
    if (all >= K) {
      res = 1;
      return;
    }
  }
  for (int i = 0; i < G[u].size(); i++) {
    int v = G[u][i];
    if (v == p) continue;
    if (a[u] < now)
      up[v] = 0;
    else {
      int tmp = f[u], mx = 0;
      if (cnt[v] == siz[v]) tmp -= down[v];
      for (int j = 0; j < 2; j++) {
        if (son[u][j].second != v) mx = max(mx, son[u][j].first);
      }
      if (cnt[1] - cnt[u] == siz[1] - siz[u])
        tmp += up[u];
      else
        mx = max(mx, up[u]);
      up[v] = tmp + mx + 1;
    }
    dfs3(v, u);
  }
}
int check() {
  res = 0;
  dfs1(1, 1);
  dfs2(1, 1);
  dfs3(1, 1);
  return res;
}
int solve(int n) {
  int l = 1, r = 1000001, m;
  while (r - l > 1) {
    now = m = l + r >> 1;
    if (check())
      l = m;
    else
      r = m;
  }
  return l;
}
int main() {
  int n;
  scanf("%d %d", &n, &K);
  for (int i = 1; i <= n; i++) scanf("%d", a + i);
  for (int i = 1, u, v; i < n; i++) {
    scanf("%d %d", &u, &v);
    G[u].push_back(v);
    G[v].push_back(u);
  }
  printf("%d\n", solve(n));
  return 0;
}
