#include <bits/stdc++.h>
using namespace std;
struct Edge {
  int u, v, next;
  Edge() {}
  Edge(int _u, int _v, int _nt) : u(_u), v(_v), next(_nt) {}
} edge[200010 << 1];
int n, k, a[200010], head[200010], tot, f[200010], fa[200010], st[200010],
    siz[200010], v[200010], top;
void link(int xx, int yy) {
  edge[++tot] = Edge(xx, yy, head[xx]);
  head[xx] = tot;
}
void DFS(int x) {
  siz[x] = 1;
  for (int i = head[x]; i != 0; i = edge[i].next) {
    int nt = edge[i].v;
    if (fa[x] == nt) continue;
    fa[nt] = x;
    DFS(nt);
    siz[x] += siz[nt];
  }
  st[++top] = x;
}
bool check(int vl) {
  for (int i = 1; i <= n; i++) v[i] = (a[i] >= vl), f[i] = 0;
  for (int i = 1; i <= n; i++) v[fa[st[i]]] += v[st[i]];
  for (int i = 1; i <= n; i++) {
    int x = st[i], sum = 0;
    if (a[x] < vl) continue;
    for (int i = head[x]; i != 0; i = edge[i].next) {
      int nt = edge[i].v;
      if (fa[x] == nt) continue;
      if (siz[nt] == v[nt]) sum += v[nt];
    }
    if (n - siz[x] == v[1] - v[x]) sum += (v[1] - v[x]);
    f[x] = 1;
    for (int i = head[x]; i != 0; i = edge[i].next) {
      int nt = edge[i].v;
      if (nt == fa[x] || siz[nt] == v[nt]) continue;
      if (f[x] + f[nt] + sum >= k) return true;
      f[x] = max(f[x], f[nt] + 1);
    }
    if (f[x] + sum >= k) return true;
    f[x] += sum;
    if (n - siz[x] == v[1] - v[x]) f[x] -= (v[1] - v[x]);
  }
  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; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    link(x, y), link(y, x);
  }
  int l = 1, r = 1000000;
  DFS(1);
  check(2);
  while (l < r) {
    int mid = (l + r + 1) >> 1;
    if (check(mid))
      l = mid;
    else
      r = mid - 1;
  }
  printf("%d\n", l);
  return 0;
}
