#include <bits/stdc++.h>
using namespace std;
const int N = 2E5 + 5;
int n, a[N], x, y, l, r, mid, f[N], ans, k;
bool o[N];
vector<int> G[N];
void dfs(int x, int fa) {
  int y, maxi = 0;
  o[x] = f[x] = 1;
  for (int i = 0; i < G[x].size(); i++)
    if ((y = G[x][i]) != fa) {
      dfs(y, x);
      if (!o[y]) {
        o[x] = 0;
        maxi = max(maxi, f[y]);
      } else
        f[x] += f[y];
    }
  f[x] += maxi;
  if (a[x] < mid) o[x] = f[x] = 0;
}
void dfs2(int x, int fa, int sum, bool o2) {
  if (fa && a[fa] < mid) sum = o2 = 0;
  int y, u = 0, v = 0, tot;
  for (int i = 0; i < G[x].size(); i++)
    if ((y = G[x][i]) != fa && !o[y]) {
      if (f[y] > f[u])
        v = u, u = y;
      else if (f[y] > f[v])
        v = y;
    }
  if (a[x] < mid)
    o2 = 0;
  else {
    tot = f[x] - f[u];
    if (o2)
      tot += sum;
    else
      tot += max(sum, f[u]);
    ans = max(ans, tot);
  }
  for (int i = 0; i < G[x].size(); i++)
    if ((y = G[x][i]) != fa) {
      tot = f[x] - f[y] - f[u];
      if (o2) tot += sum;
      if (y == u) {
        tot += f[u];
        if (!o2)
          tot += max(f[v], sum);
        else
          tot += f[v];
        dfs2(y, x, tot, o2 & (v == 0));
      } else if (y == v) {
        if (!o2)
          tot += max(f[u], sum);
        else
          tot += f[u];
        dfs2(y, x, tot, 0);
      } else {
        if (!o2)
          tot += max(f[u], sum);
        else
          tot += f[u];
        dfs2(y, x, tot, o2 & (u == 0));
      }
    }
}
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]), r = max(r, a[i]);
  for (int i = 1; i < n; i++) {
    scanf("%d%d", &x, &y);
    G[x].push_back(y);
    G[y].push_back(x);
  }
  r++;
  while (l < r) {
    mid = (l + r) / 2;
    dfs(1, 0);
    ans = 0;
    dfs2(1, 0, 0, 1);
    if (ans < k)
      r = mid;
    else
      l = mid + 1;
  }
  cout << l - 1;
}
