#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
struct edge {
  int to, next;
  edge(int to = 0, int next = 0) : to(to), next(next) {}
} G[maxn << 1];
int head[maxn], tot, pre[maxn], a[maxn], dp[maxn][2], sz[maxn], n, k, m,
    que[maxn];
void init() {
  memset(head, -1, sizeof(head));
  tot = 0;
}
void addedge(int u, int v) {
  G[tot] = edge(v, head[u]);
  head[u] = tot++;
  G[tot] = edge(u, head[v]);
  head[v] = tot++;
}
bool dfs(int u, int fa) {
  bool ret = a[u] >= m;
  dp[u][0] = dp[u][1] = -1;
  sz[u] = 0;
  pre[u] = fa;
  for (int i = head[u]; ~i; i = G[i].next) {
    int v = G[i].to;
    if (v == fa) continue;
    bool tmp = dfs(v, u);
    ret &= tmp;
    if (a[u] >= m) {
      if (tmp)
        sz[u] += sz[v] + 1;
      else if (dp[u][0] <= dp[v][0] + sz[v] + 1) {
        dp[u][1] = dp[u][0];
        dp[u][0] = dp[v][0] + sz[v] + 1;
      } else if (dp[u][1] < dp[v][0] + sz[v] + 1)
        dp[u][1] = dp[v][0] + sz[v] + 1;
    }
  }
  return ret;
}
bool bfs(int s) {
  int front = 0, rear = 0;
  que[rear++] = s;
  while (front < rear) {
    int u = que[front++], fa = pre[u];
    if (a[u] >= m && max(dp[u][0], 0) + sz[u] + 1 >= k) return true;
    for (int i = head[u]; ~i; i = G[i].next) {
      int v = G[i].to;
      if (v == fa) continue;
      que[rear++] = v;
      if (a[u] >= m && a[v] >= m) {
        if (dp[u][1] == -1 && ~dp[v][0])
          sz[v] += sz[u] + 1;
        else {
          int tmp1 = dp[u][0] == dp[v][0] + sz[v] + 1 ? dp[u][1] : dp[u][0];
          int tmp2 = ~dp[v][0] ? sz[u] + 1 : sz[u] - sz[v];
          if (dp[v][0] <= tmp1 + tmp2) {
            dp[v][1] = dp[v][0];
            dp[v][0] = tmp1 + tmp2;
          } else if (dp[v][1] < tmp1 + tmp2)
            dp[v][1] = tmp1 + tmp2;
        }
      }
    }
  }
  return false;
}
int main() {
  while (~scanf("%d%d", &n, &k)) {
    init();
    int _max = 0;
    for (int i = 1; i <= n; ++i) {
      scanf("%d", &a[i]);
      _max = max(_max, a[i]);
    }
    for (int i = 1; i < n; ++i) {
      int u, v;
      scanf("%d%d", &u, &v);
      addedge(u, v);
    }
    int l = 1, r = _max;
    while (l < r) {
      m = (l + r + 1) >> 1;
      dfs(1, 0);
      bfs(1) ? l = m : r = m - 1;
    }
    printf("%d\n", l);
  }
  return 0;
}
