#include <bits/stdc++.h>
using namespace std;
int n, k, best1[200005], best2[200005], dp[200005], size[200005], temp[200005],
    a[200005], tot[200005], got;
vector<int> v[200005];
void dfs(int cur, int par) {
  size[cur] = 1;
  tot[cur] = temp[cur];
  for (int i = 0; i < v[cur].size(); i++) {
    int x = v[cur][i];
    if (x == par) continue;
    dfs(x, cur);
    size[cur] += size[x];
    tot[cur] += tot[x];
  }
}
void dfs_down(int cur, int par) {
  best1[cur] = 0;
  best2[cur] = 0;
  dp[cur] = 0;
  for (int i = 0; i < v[cur].size(); i++) {
    int x = v[cur][i];
    if (x == par) continue;
    dfs_down(x, cur);
    if (size[x] == tot[x])
      dp[cur] += size[x];
    else if (dp[x] > best1[cur]) {
      best2[cur] = best1[cur];
      best1[cur] = dp[x];
    } else
      best2[cur] = max(best2[cur], dp[x]);
  }
  if (temp[cur]) {
    dp[cur] += 1;
    dp[cur] += best1[cur];
  } else {
    dp[cur] = 0;
    best1[cur] = 0;
    best2[cur] = 0;
  }
}
void dfs_up(int cur, int par, int up_val) {
  if (up_val == n - size[cur])
    dp[cur] += up_val;
  else {
    dp[cur] -= best1[cur];
    if (up_val > best1[cur]) {
      best2[cur] = best1[cur];
      best1[cur] = up_val;
    } else
      best2[cur] = max(best2[cur], up_val);
    dp[cur] += best1[cur];
  }
  if (!temp[cur]) {
    dp[cur] = 0;
    best1[cur] = 0;
    best2[cur] = 0;
  }
  got = got | (dp[cur] >= k);
  for (int i = 0; i < v[cur].size(); i++) {
    int x = v[cur][i];
    if (x == par) continue;
    if (size[x] == tot[x])
      dfs_up(x, cur, dp[cur] - size[x]);
    else if (best1[cur] == dp[x])
      dfs_up(x, cur, dp[cur] - best1[cur] + best2[cur]);
    else
      dfs_up(x, cur, dp[cur]);
  }
}
int ok(int val) {
  got = 0;
  for (int i = 1; i <= n; i++) temp[i] = (a[i] >= val);
  dfs(1, -1);
  dfs_down(1, -1);
  dfs_up(1, -1, 0);
  return got;
}
int main() {
  ios::sync_with_stdio(false);
  ;
  cin.tie(0);
  ;
  int i, lo, mid, hi, x, y;
  cin >> n >> k;
  for (i = 1; i <= n; i++) cin >> a[i];
  for (i = 1; i <= n - 1; i++) {
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  lo = 1;
  hi = 1000001;
  while (hi - lo > 1) {
    mid = (lo + hi) / 2;
    if (ok(mid))
      lo = mid;
    else
      hi = mid;
  }
  cout << lo;
  return 0;
}
