#include <bits/stdc++.h>
using namespace std;
vector<int> v[200008];
int val[200008];
int n, tk;
int dp[200008];
int lim;
int siz[200008];
int cnt, tot;
int no[200008];
void dfs(int x, int p) {
  no[x] = val[x] < lim;
  dp[x] = 0;
  int b1 = 0, b2 = 0, b3 = 0;
  siz[x] = 1;
  for (int i = 0; i < v[x].size(); i++) {
    int y = v[x][i];
    if (y == p) continue;
    dfs(y, x);
    siz[x] += siz[y], no[x] += no[y];
    if (no[y] == 0)
      b3 += siz[y];
    else {
      if (dp[y] > b1)
        b2 = b1, b1 = dp[y];
      else
        b2 = max(b2, dp[y]);
    }
  }
  if (val[x] < lim) return;
  dp[x] = b1 + b3 + 1;
  if (tot == no[x])
    cnt = max(cnt, 1 + n - siz[x] + b1 + b2 + b3);
  else
    cnt = max(cnt, 1 + b1 + b2 + b3);
}
int check(int mid) {
  lim = mid;
  cnt = 0;
  tot = 0;
  for (int i = 1; i <= n; i++)
    if (val[i] < lim) tot++;
  dfs(1, 0);
  return cnt >= tk;
}
int main() {
  scanf("%d%d", &n, &tk);
  for (int i = 1; i <= n; i++) scanf("%d", &val[i]);
  for (int i = 1; i < n; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    v[x].push_back(y);
    v[y].push_back(x);
  }
  int l = 0, r = 1000000;
  int ans = -1;
  while (l <= r) {
    int mid = (l + r) / 2;
    if (check(mid))
      ans = mid, l = mid + 1;
    else
      r = mid - 1;
  }
  cout << ans;
  return 0;
}
