#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 7;
int n, k;
int a[maxn], w[maxn], sz[maxn], up[maxn], dp[maxn];
vector<int> E[maxn];
int flag;
void dfs1(int x, int fa, int m) {
  sz[x] = 1;
  for (int i = 0; i < E[x].size(); i++) {
    int v = E[x][i];
    if (v == fa) continue;
    dfs1(v, x, m);
    sz[x] += sz[v];
    w[x] += w[v];
  }
}
void dfs2(int x, int fa, int m) {
  int Max1 = 0, Max2 = 0, tot = 0;
  for (int i = 0; i < E[x].size(); i++) {
    int v = E[x][i];
    if (v == fa) continue;
    if (w[x] - w[v] == sz[x] - sz[v] && up[x]) up[v] = 1;
    dfs2(v, x, m);
    if (a[v] < m) continue;
    if (sz[v] == w[v]) {
      tot += sz[v];
    } else {
      if (dp[v] > Max1)
        Max2 = Max1, Max1 = dp[v];
      else if (dp[v] > Max2)
        Max2 = dp[v];
    }
  }
  if (a[x] < m) return;
  if (tot + Max1 + Max2 + up[x] * (n - sz[x]) + 1 >= k) flag = 1;
  dp[x] = tot + Max1 + 1;
}
int check(int x) {
  for (int i = 1; i <= n; i++) dp[i] = up[i] = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i] >= x)
      w[i] = 1;
    else
      w[i] = 0;
  }
  flag = 0;
  dfs1(1, -1, x);
  up[1] = w[1];
  dfs2(1, -1, x);
  return flag;
}
void input() {
  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);
    E[x].push_back(y);
    E[y].push_back(x);
  }
}
void work() {
  int l = 0, r = 1e6 + 6, ans;
  while (l <= r) {
    int mid = (l + r) / 2;
    if (check(mid))
      l = mid + 1, ans = mid;
    else
      r = mid - 1;
  }
  printf("%d\n", ans);
}
int main() {
  input();
  work();
  return 0;
}
