#include <bits/stdc++.h>
using namespace std;
int n, k, a[200010], sz[200010], cnt, fa[200010], head[200010], num[200010],
    f[200010], ans;
int st[200010], top;
struct edge {
  int to, next;
} e[500010];
inline void insert(int u, int v) {
  e[++cnt].to = v, e[cnt].next = head[u], head[u] = cnt;
}
inline void dfs(int u) {
  sz[u] = 1;
  for (int i = head[u]; i; i = e[i].next) {
    int v = e[i].to;
    if (v == fa[u]) continue;
    fa[v] = u;
    dfs(v);
    sz[u] += sz[v];
  }
  st[++top] = u;
}
inline bool check(int x) {
  for (int i = 1; i <= n; i++) num[i] = (a[i] >= x), f[i] = 0;
  for (int i = 1; i <= top; i++) {
    int t = st[i];
    if (fa[t]) num[fa[t]] += num[t];
  }
  for (int i = 1; i <= top; i++) {
    if (a[st[i]] < x) continue;
    int sum = 0, u = st[i];
    for (int i = head[u]; i; i = e[i].next) {
      int v = e[i].to;
      if (v == fa[u]) continue;
      if (sz[v] == num[v]) sum += sz[v];
    }
    if (sz[1] - sz[u] == num[1] - num[u]) sum += sz[1] - sz[u];
    f[u] = 1;
    for (int i = head[u]; i; i = e[i].next) {
      int v = e[i].to;
      if (v == fa[u] || num[v] == sz[v]) continue;
      if (f[u] + f[v] + sum >= k) return true;
      f[u] = max(f[u], f[v] + 1);
    }
    if (f[u] + sum >= k) return true;
    f[u] += sum;
    if (sz[1] - sz[u] == num[1] - num[u]) f[u] -= sz[1] - sz[u];
  }
  return false;
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= n - 1; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    insert(u, v);
    insert(v, u);
  }
  dfs(1);
  int l = 0, r = 1000000;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (check(mid))
      ans = mid, l = mid + 1;
    else
      r = mid - 1;
  }
  printf("%d\n", ans);
  return 0;
}
