#include <bits/stdc++.h>
using namespace std;
int n, m, a[200005], b[200005], s[200005], t[200005], dp[200005];
vector<int> v[200005];
bool flag;
void dfs(int x, int y) {
  s[x] = 1;
  dp[x] = t[x] = b[x];
  int best = 0;
  for (int i = (0); i < (v[x].size()); i++) {
    int V = v[x][i];
    if (V == y) continue;
    dfs(V, x);
    s[x] += s[V];
    t[x] += t[V];
    if (s[V] == t[V])
      dp[x] += s[V];
    else
      best = max(best, dp[V]);
  }
  dp[x] += best;
  if (!b[x]) dp[x] = 0;
}
void dfs2(int x, int y) {
  int best = 0, ch = -1, sec = 0;
  dp[x] = t[x] = b[x];
  s[x] = 1;
  for (int i = (0); i < (v[x].size()); i++) {
    int V = v[x][i];
    s[x] += s[V];
    t[x] += t[V];
    if (s[V] > t[V]) {
      if (best <= dp[V]) {
        sec = best;
        best = dp[V];
        ch = V;
      } else if (dp[V] > sec)
        sec = dp[V];
    } else
      dp[x] += s[V];
  }
  dp[x] += best;
  if (!b[x]) dp[x] = 0;
  if (dp[x] >= m) flag = 1;
  for (int i = (0); i < (v[x].size()); i++) {
    int V = v[x][i];
    if (V == y) continue;
    int ori = dp[x], ot = t[x], os = s[x];
    if (s[V] == t[V])
      dp[x] -= t[V];
    else if (ch == V)
      dp[x] -= best - sec;
    if (!b[x]) dp[x] = 0;
    t[x] -= t[V];
    s[x] -= s[V];
    dfs2(V, x);
    dp[x] = ori;
    t[x] = ot;
    s[x] = os;
  }
}
bool ok(int l) {
  for (int i = (1); i <= (n); i++) b[i] = a[i] >= l;
  dfs(1, 0);
  flag = 0;
  dfs2(1, 0);
  return flag;
}
int main() {
  scanf("%d %d", &n, &m);
  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);
    v[x].push_back(y);
    v[y].push_back(x);
  }
  int l = 1, h = 1000000;
  while (l < h) {
    int m = l + h + 1 >> 1;
    if (ok(m))
      l = m;
    else
      h = m - 1;
  }
  printf("%d\n", l);
}
