#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int mid, n, m, w[N], f[N], sz[N], ans = 0;
vector<int> e[N];
void dfs(int u, int fa) {
  f[u] = sz[u] = 1;
  int mx1 = 0, mx2 = 0;
  for (auto &v : e[u]) {
    if (v == fa) continue;
    dfs(v, u);
    sz[u] += sz[v];
    if (f[v] == sz[v])
      f[u] += f[v];
    else {
      if (f[v] > mx1) swap(f[v], mx1);
      if (f[v] > mx2) swap(f[v], mx2);
    }
  }
  f[u] = w[u] < mid ? 0 : f[u] + mx1;
  ans = max(ans, f[u] + mx2);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &w[i]);
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    e[u].push_back(v), e[v].push_back(u);
  }
  int rt = min_element(w + 1, w + n + 1) - w;
  int l = *min_element(w + 1, w + n + 1), r = *max_element(w + 1, w + n + 1);
  while (l <= r) {
    mid = (l + r) >> 1;
    dfs(rt, ans = 0);
    if (ans >= m)
      l = mid + 1;
    else
      r = mid - 1;
  }
  printf("%d\n", l - 1);
  return 0;
}
