#include <bits/stdc++.h>
using namespace std;
const int MaxN = 400010;
class Graph {
 public:
  int en[MaxN], next[MaxN], point[MaxN], tot;
  void init() { tot = 1; }
  void add_edge(int x, int y) {
    next[++tot] = en[x];
    en[x] = tot;
    point[tot] = y;
  }
} G;
int n, k, a[MaxN];
int q[MaxN], father[MaxN], deg[MaxN];
int f_up[MaxN], f_down[MaxN], mx[MaxN], sc[MaxN], g[MaxN];
int c_up[MaxN], c_down[MaxN];
void bfs(int root) {
  static bool vis[MaxN];
  int l = 0, r = 0;
  q[++r] = root;
  vis[root] = 1;
  while (l != r) {
    int u = q[++l];
    for (int i = G.en[u]; i; i = G.next[i])
      if (!vis[G.point[i]]) {
        q[++r] = G.point[i];
        vis[G.point[i]] = 1;
        father[G.point[i]] = u;
      }
  }
}
bool check(int x) {
  for (int i = n; i; --i) {
    int u = q[i];
    mx[u] = sc[u] = 0;
    f_up[u] = c_up[u] = 0;
    if (a[u] < x) continue;
    ++f_up[u];
    for (int j = G.en[u]; j; j = G.next[j])
      if ((G.point[j] != father[u]) && (a[G.point[j]] >= x)) {
        int tmp = f_up[G.point[j]];
        if (c_up[G.point[j]] == deg[G.point[j]] - 1) {
          f_up[u] += tmp;
          ++c_up[u];
        } else {
          if (tmp > mx[u]) {
            sc[u] = mx[u];
            mx[u] = tmp;
          } else if (tmp > sc[u])
            sc[u] = tmp;
        }
      }
    f_up[u] += mx[u];
  }
  memcpy(g, f_up, sizeof(f_up));
  memcpy(c_down, c_up, sizeof(c_up));
  for (int i = 2; i <= n; ++i) {
    int u = q[i], f = father[u], down = g[f];
    if (min(a[u], a[f]) < x) continue;
    if (c_up[u] == deg[u] - 1)
      down -= f_up[u];
    else if (f_up[u] == mx[f])
      down -= mx[f] - sc[f];
    if (c_down[f] - (c_up[u] == deg[u] - 1) == deg[f] - 1) {
      ++c_down[u];
      g[u] += down;
    } else if (down > mx[u]) {
      g[u] += down - mx[u];
      sc[u] = mx[u];
      mx[u] = down;
    }
  }
  for (int i = 1; i <= n; ++i)
    if (a[i] >= x)
      if (g[i] >= k) return 1;
  return 0;
}
int main() {
  G.init();
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; ++i) scanf("%d", a + i);
  for (int i = 1; i < n; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    G.add_edge(u, v);
    G.add_edge(v, u);
    ++deg[u];
    ++deg[v];
  }
  bfs(1);
  int l = 1, r = 1000000;
  while (l != r) {
    int mid = (l + r + 1) >> 1;
    if (check(mid))
      l = mid;
    else
      r = mid - 1;
  }
  cout << l << endl;
  return 0;
}
