#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int n, k, a[N], b[N], siz[N], f[N], g[N], l, r, mid, ans, tag;
vector<int> G[N];
inline int read() {
  int f = 1, x = 0;
  char ch = getchar();
  while (ch > '9' || ch < '0') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return f * x;
}
inline void dfs1(int u, int fa) {
  siz[u] = 1, f[u] = 1;
  int tmp1 = 0, tmp2 = 0;
  for (auto v : G[u])
    if (v ^ fa) {
      dfs1(v, u);
      siz[u] += siz[v];
      if (f[v] == siz[v])
        tmp1 += f[v];
      else
        tmp2 = max(tmp2, f[v]);
    }
  f[u] += tmp1 + tmp2;
  if (a[u] < b[mid]) f[u] = 0;
}
inline void dfs2(int u, int fa) {
  int t1 = 0, t2 = 0, t3 = 0;
  if (g[u] == n - siz[u])
    t1 += g[u];
  else
    t2 = max(t2, g[u]);
  for (auto v : G[u])
    if (v ^ fa) {
      if (f[v] == siz[v])
        t1 += f[v];
      else if (f[v] >= t2)
        t3 = t2, t2 = f[v];
      else if (f[v] >= t3)
        t3 = f[v];
    }
  if (a[u] >= b[mid])
    if (t1 + t2 + 1 >= k) tag = 1;
  for (auto v : G[u])
    if (v ^ fa) {
      if (a[v] >= b[mid] && a[u] >= b[mid]) {
        if (f[v] == siz[v])
          g[v] = t1 + t2 - f[v] + 1;
        else if (f[v] == t2)
          g[v] = t1 + t3 + 1;
        else
          g[v] = t1 + t2 + 1;
      }
      dfs2(v, u);
    }
}
inline bool check() {
  tag = 0;
  for (int i = (1), iend = (n); i <= iend; i++) f[i] = g[i] = 0;
  dfs1(1, 0);
  dfs2(1, 0);
  return tag;
}
int main() {
  n = read(), k = read();
  for (int i = (1), iend = (n); i <= iend; i++) b[i] = a[i] = read();
  for (int i = (2), iend = (n); i <= iend; i++) {
    int x = read(), y = read();
    G[x].push_back(y), G[y].push_back(x);
  }
  sort(b + 1, b + n + 1);
  l = 1, r = ans = n;
  while (l <= r) {
    mid = (l + r) >> 1;
    if (check())
      ans = mid, l = mid + 1;
    else
      r = mid - 1;
  }
  printf("%d", b[ans]);
  return 0;
}
