#include <bits/stdc++.h>
using namespace std;
long long t, n, m, u, v, q, r, ql, qr, k, l, s, w, z, x, y, d;
const int N = 2e5 + 500;
const int LN = 20;
const long long mod = 1e9 + 7;
const long long INF = 1LL << 52LL;
bool mn[N], pmn[N];
int a[N], dp[N], sz[N];
int full[N];
vector<int> max_pref[N];
vector<int> adj[N];
int sol = 0;
void dfs(int v, int p, int val) {
  max_pref[v].push_back(0);
  mn[v] = true;
  sz[v] = 1;
  for (int u : adj[v]) {
    if (u == p) continue;
    dfs(u, v, val);
    mn[v] &= mn[u];
    if (mn[u])
      full[v] += sz[u];
    else {
      max_pref[v].push_back(dp[u]);
    }
    sz[v] += sz[u];
  }
  full[v]++;
  if (a[v] < val) {
    mn[v] = full[v] = dp[v] = 0;
    max_pref[v].clear();
    max_pref[v].push_back(0);
    return;
  }
  sort(max_pref[v].begin(), max_pref[v].end());
  reverse(max_pref[v].begin(), max_pref[v].end());
  dp[v] = full[v] + max_pref[v][0];
}
void dfs2(int v, int p, int val, bool pd, int ss) {
  if (a[v] < val) {
  } else {
    if (pd) {
      sol = max(sol, full[v] + max_pref[v][0] + ss);
    } else {
      sol = max(sol, full[v] + max(max_pref[v][0], ss));
    }
  }
  if (a[v] >= val && pd)
    full[v] += ss;
  else if (a[v] >= val) {
    max_pref[v].push_back(ss);
    sort(max_pref[v].begin(), max_pref[v].end());
    reverse(max_pref[v].begin(), max_pref[v].end());
  }
  for (int u : adj[v]) {
    if (u == p) continue;
    if (mn[u]) {
      dfs2(u, v, val, (full[v] == n),
           max(0, (full[v] - sz[u]) + max_pref[v][0]));
    } else {
      dfs2(u, v, val, (n - full[v] == sz[u]),
           full[v] +
               (dp[u] == max_pref[v][0] ? max_pref[v][1] : max_pref[v][0]));
    }
  }
}
bool check(int val) {
  for (int i = 1; i <= n; ++i) {
    max_pref[i].clear();
    dp[i] = 0;
    mn[i] = false;
    full[i] = 0;
    sz[i] = 0;
  }
  dfs(1, 0, val);
  sol = 0;
  dfs2(1, 0, val, true, 0);
  return (sol >= k);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> k;
  int lo = INT_MAX;
  int hi = -lo;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    lo = min(lo, a[i]);
    hi = max(hi, a[i]);
  }
  for (int i = 0; i < n - 1; ++i) {
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  while (lo < hi) {
    int mid = (lo + hi + 1) / 2;
    if (check(mid))
      lo = mid;
    else
      hi = mid - 1;
  }
  cout << lo << '\n';
  return 0;
}
