#include <bits/stdc++.h>
using namespace std;
long long int all_up[200001], n, req, val, dp_up[200001], dp_down[200001],
    size[200001], mini[200001], all_sum[200001], all_down[200001];
long long int a[200001], max1_not_full[200001], max2_not_full[200001];
vector<long long int> v[200001];
void dfs_down(long long int cur, long long int par) {
  mini[cur] = a[cur];
  size[cur] = 1;
  for (int i = 0; i < v[cur].size(); i++) {
    int x = v[cur][i];
    if (x == par) continue;
    dfs_down(x, cur);
    mini[cur] = min(mini[cur], mini[x]);
    size[cur] += size[x];
  }
  if (a[cur] < val)
    dp_down[cur] = 0;
  else {
    dp_down[cur] = 1;
    long long int maxi = 0;
    for (int i = 0; i < v[cur].size(); i++) {
      int x = v[cur][i];
      if (x == par) continue;
      if (dp_down[x] == size[x])
        dp_down[cur] += dp_down[x];
      else
        maxi = max(maxi, dp_down[x]);
    }
    dp_down[cur] += maxi;
  }
  if (dp_down[cur] == size[cur])
    all_down[cur] = 1;
  else
    all_down[cur] = 0;
  all_sum[cur] = 0;
  max1_not_full[cur] = -1;
  max2_not_full[cur] = -1;
  for (int i = 0; i < v[cur].size(); i++) {
    int x = v[cur][i];
    if (x == par) continue;
    if (dp_down[x] == size[x])
      all_sum[cur] += dp_down[x];
    else {
      if (max1_not_full[cur] == -1 ||
          dp_down[max1_not_full[cur]] <= dp_down[x]) {
        max2_not_full[cur] = max1_not_full[cur];
        max1_not_full[cur] = x;
      } else if (max2_not_full[cur] == -1 ||
                 dp_down[max2_not_full[cur]] <= dp_down[x])
        max2_not_full[cur] = x;
    }
  }
}
void dfs_up(long long int cur, long long int par) {
  if (par != -1) {
    if (a[cur] < val)
      dp_up[cur] = 0;
    else if (a[par] < val)
      dp_up[cur] = 1;
    else {
      dp_up[cur] = 2;
      dp_up[cur] += all_sum[par];
      if (dp_down[cur] == size[cur]) dp_up[cur] -= dp_down[cur];
      if (all_up[par]) {
        if (dp_up[par] >= 1) dp_up[cur] += dp_up[par] - 1;
        if (max1_not_full[par] != -1 && max1_not_full[par] != cur)
          dp_up[cur] += dp_down[max1_not_full[par]];
        else if (max2_not_full[par] != -1 && max2_not_full[par] != cur)
          dp_up[cur] += dp_down[max2_not_full[par]];
      } else {
        if (max1_not_full[par] == -1)
          dp_up[cur] += max(0LL, dp_up[par] - 1);
        else if (max1_not_full[par] == cur) {
          if (max2_not_full[par] == -1)
            dp_up[cur] += max(0LL, dp_up[par] - 1);
          else
            dp_up[cur] +=
                max(max(0LL, dp_up[par] - 1), dp_down[max2_not_full[par]]);
        } else
          dp_up[cur] +=
              max(max(0LL, dp_up[par] - 1), dp_down[max1_not_full[par]]);
      }
    }
    if (dp_up[cur] == n - size[cur] + 1) all_up[cur] = 1;
  }
  for (int i = 0; i < v[cur].size(); i++) {
    int x = v[cur][i];
    if (x == par) continue;
    dfs_up(x, cur);
  }
}
int ok(long long int to_check) {
  val = to_check;
  memset(all_up, 0, sizeof all_up);
  memset(all_down, 0, sizeof all_down);
  dfs_down(1, -1);
  dfs_up(1, -1);
  for (int i = 1; i <= n; i++) {
    if (a[i] < val) continue;
    if (dp_up[i] + dp_down[i] - 1 >= req) return 1;
  }
  return 0;
}
int main() {
  ios::sync_with_stdio(false);
  ;
  cin.tie(0);
  ;
  long long int i, j, lo, mid, hi, x, y;
  cin >> n >> req;
  lo = 1000000000000;
  hi = 0;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    lo = min(lo, a[i]);
    hi = max(hi, a[i]);
  }
  for (i = 1; i <= n - 1; i++) {
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  lo = 0;
  hi++;
  while (hi - lo > 1) {
    mid = (lo + hi) / 2;
    if (ok(mid))
      lo = mid;
    else
      hi = mid;
  }
  cout << lo;
  return 0;
}
