#include <bits/stdc++.h>
using namespace std;
const int mod = 1000 * 1000 * 1000 + 7;
const int INF = 1e9 + 100;
const long long LINF = 1e18 + 100;
int n, k;
int a[200100];
vector<int> adj[200100];
int dp[200100], subtree[200100];
bool dfs(int v, int par, int x) {
  subtree[v] = 1;
  int mx = 0, mx2 = 0;
  for (int u : adj[v])
    if (u != par) {
      if (dfs(u, v, x)) return true;
      subtree[v] += subtree[u];
      if (dp[u] == subtree[u])
        dp[v] += dp[u];
      else {
        if (dp[u] > mx)
          mx2 = mx, mx = dp[u];
        else
          mx2 = max(mx2, dp[u]);
      }
    }
  if (a[v] < x)
    dp[v] = 0;
  else {
    dp[v] += mx + 1;
    if (dp[v] + mx2 >= k) return true;
  }
  return false;
}
int32_t main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n >> k;
  for (int i = (1); i < (int)(n + 1); i++) cin >> a[i];
  for (int i = (0); i < (int)(n - 1); i++) {
    int x, y;
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  int rt = min_element(a + 1, a + n + 1) - a;
  int l = 0, r = 1e6 + 100;
  while (r - l > 1) {
    int mid = (r + l) / 2;
    memset(dp, 0, sizeof(dp));
    if (dfs(rt, -1, mid))
      l = mid;
    else
      r = mid;
  }
  cout << l << '\n';
  return 0;
}
