#include <bits/stdc++.h>
using namespace std;
int n, m, l, r, mid, ans, K, x, y, s[200005], f[200005], g[200005], mx[200005],
    a[200005];
vector<int> e[200005];
void dfs(int x, int y) {
  s[x] = 1;
  f[x] = 0;
  mx[x] = 0;
  for (int i = 0; i < e[x].size(); ++i)
    if (e[x][i] != y) {
      dfs(e[x][i], x);
      s[x] += s[e[x][i]];
      if (f[e[x][i]] == s[e[x][i]])
        f[x] += f[e[x][i]];
      else if (f[mx[x]] < f[e[x][i]])
        mx[x] = e[x][i];
    }
  f[x] += f[mx[x]];
  if (a[x] < mid)
    f[x] = 0;
  else
    ++f[x];
}
void fly(int x, int y) {
  for (int i = 0; i < e[x].size(); ++i)
    if (e[x][i] != y) {
      g[e[x][i]] = f[x];
      if (g[x] == n - s[x]) g[e[x][i]] += g[x];
      if (f[e[x][i]] == s[e[x][i]]) g[e[x][i]] -= f[e[x][i]];
      if (mx[x] == e[x][i]) {
        g[e[x][i]] -= f[e[x][i]];
        int w = 0;
        for (int j = 0; j < e[x].size(); ++j)
          if (e[x][j] != y && e[x][j] != mx[x] && f[e[x][j]] != s[e[x][j]])
            w = max(w, f[e[x][j]]);
        if (g[x] != n - s[x]) w = max(w, g[x]);
        g[e[x][i]] += w;
      }
      if (a[x] < mid) g[e[x][i]] = 0;
      fly(e[x][i], x);
      if (ans >= K) return;
    }
  if (a[x] < mid) return;
  int u = 1, w = 0;
  for (int i = 0; i < e[x].size(); ++i)
    if (e[x][i] != y) {
      if (f[e[x][i]] == s[e[x][i]])
        u += f[e[x][i]];
      else
        w = max(w, f[e[x][i]]);
    }
  if (g[x] == n - s[x])
    u += g[x];
  else
    w = max(w, g[x]);
  ans = max(ans, u + w);
}
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) {
    scanf("%d%d", &x, &y);
    e[x].push_back(y);
    e[y].push_back(x);
  }
  l = 1;
  r = 1000000;
  while (l < r) {
    mid = l + r + 1 >> 1;
    dfs(1, 0);
    ans = 0;
    fly(1, 0);
    if (ans >= K)
      l = mid;
    else
      r = mid - 1;
  }
  printf("%d\n", l);
  return 0;
}
