#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int k, a[N], dp[N], sz[N];
vector<int> adj[N];
bool mark[N];
bool dfs(int x, int u, int par = -1) {
  bool ok = false;
  int mx1 = 0, mx2 = 0;
  mark[u] = sz[u] = dp[u] = 1;
  for (auto v : adj[u])
    if (v ^ par) {
      ok |= dfs(x, v, u), sz[u] += sz[v], dp[u] += mark[v] * sz[v],
          mark[u] &= mark[v];
      if (!mark[v] && dp[v] > mx1)
        swap(mx1, mx2), mx1 = dp[v];
      else if (!mark[v])
        mx2 = max(dp[v], mx2);
    }
  if (a[u] < x) mark[u] = dp[u] = mx1 = mx2 = 0;
  return (dp[u] += mx1) + mx2 >= k || ok;
}
int main() {
  ios_base ::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int n;
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  int root = 0;
  for (int i = 0; i < n; i++)
    if (a[i] < a[root]) root = i;
  int L = a[root], R = 1e6 + 10;
  while (L + 1 < R) {
    int mid = L + R >> 1;
    dfs(mid, root) ? L = mid : R = mid;
  }
  cout << L << endl;
  return 0;
}
