#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int n, kk;
int dp[N], sz[N], ans, a[N];
vector<int> v[N];
void dfs(int pos, int fa, int mid) {
  sz[pos] = 1;
  dp[pos] = 1;
  int mx1 = 0, mx2 = 0;
  for (auto &i : v[pos])
    if (i != fa) {
      dfs(i, pos, mid);
      sz[pos] += sz[i];
      if (dp[i] == sz[i])
        dp[pos] += dp[i];
      else if (dp[i] > mx1)
        mx2 = mx1, mx1 = dp[i];
      else if (dp[i] > mx2)
        mx2 = dp[i];
    }
  if (a[pos] < mid) {
    dp[pos] = 0;
    return;
  }
  dp[pos] += mx1;
  ans = max(ans, dp[pos] + mx2);
}
int rt;
bool check(int mid) {
  ans = 0;
  dfs(rt, 0, mid);
  return ans >= kk;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> kk;
  for (int i = 1; i <= n; i++) cin >> a[i];
  int t1, t2;
  for (int i = 1; i < n; i++) {
    cin >> t1 >> t2;
    v[t1].push_back(t2);
    v[t2].push_back(t1);
  }
  int l = *min_element(a + 1, a + n + 1), r = *max_element(a + 1, a + n + 1),
      ans = -1;
  rt = min_element(a + 1, a + n + 1) - a;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (check(mid))
      ans = mid, l = mid + 1;
    else
      r = mid - 1;
  }
  cout << ans << endl;
  return 0;
}
