#include <bits/stdc++.h>
using namespace std;
const int MAXN = (1 << 20);
int n, k;
vector<int> G[MAXN];
int val[MAXN];
void read() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> val[i];
  for (int i = 1; i <= n - 1; i++) {
    int u, v;
    cin >> u >> v;
    G[u].push_back(v);
    G[v].push_back(u);
  }
}
bool visited[MAXN];
int c[MAXN];
int deg[MAXN];
queue<int> bfs_queue;
void dfs_pre(int u, int par, int d) {
  int v, sz = G[u].size();
  visited[u] = true;
  c[u] = 1;
  for (int i = 0; i < sz; i++) {
    v = G[u][i];
    if (v != par && val[v] >= d) dfs_pre(v, u, d);
  }
  if (G[u].size() == 1) bfs_queue.push(u);
}
int dist[MAXN];
int d1 = 0;
void dfs_d(int u, int par, int d) {
  int v, sz = G[u].size();
  if (dist[d1] < dist[u]) d1 = u;
  for (int i = 0; i < sz; i++) {
    v = G[u][i];
    if (v != par && val[v] >= d) {
      dist[v] = dist[u] + c[v];
      dfs_d(v, u, d);
    }
  }
}
int solve(int st, int d) {
  while (!bfs_queue.empty()) bfs_queue.pop();
  dfs_pre(st, -1, d);
  while (!bfs_queue.empty()) {
    int u = bfs_queue.front();
    bfs_queue.pop();
    int sz = G[u].size();
    for (int i = 0; i < sz; i++) {
      int v = G[u][i];
      if (deg[v] != 0 && val[v] >= d) {
        deg[v]--;
        deg[u]--;
        c[v] += c[u];
        c[u] = 0;
        if (deg[v] == 1) bfs_queue.push(v);
      }
    }
  }
  d1 = st;
  dist[st] = c[st];
  dfs_d(st, -1, d);
  dist[d1] = c[d1];
  dfs_d(d1, -1, d);
  return dist[d1];
}
bool check(int d) {
  memset(visited, false, sizeof(visited));
  memset(c, 0, sizeof(c));
  memset(dist, -1, sizeof(dist));
  while (!bfs_queue.empty()) bfs_queue.pop();
  for (int i = 1; i <= n; i++) deg[i] = G[i].size();
  for (int i = 1; i <= n; i++)
    if (!visited[i] && val[i] >= d)
      if (solve(i, d) >= k) return true;
  return false;
}
void solve() {
  int l = 0, r = MAXN + 1, mid, ans = 0;
  while (l <= r) {
    mid = (l + r) >> 1;
    if (check(mid)) {
      ans = mid;
      l = mid + 1;
    } else
      r = mid - 1;
  }
  cout << ans << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  read();
  solve();
  return 0;
}
