#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 10;
int n, k, arr[MAXN], sz[MAXN];
vector<int> adj[MAXN];
int dp_down[MAXN], dp_up[MAXN];
void dfs_down(int v, int val, int par = 0) {
  sz[v] = 1;
  dp_down[v] = 1;
  int mx = 0;
  for (auto i : adj[v])
    if (i != par) {
      dfs_down(i, val, v);
      sz[v] += sz[i];
      if (dp_down[i] == sz[i])
        dp_down[v] += dp_down[i];
      else
        mx = max(mx, dp_down[i]);
    }
  dp_down[v] += mx;
  if (arr[v] < val) dp_down[v] = 0;
  return;
}
void dfs_up(int v, int val, int par = 0, int DP = 0) {
  dp_up[v] = DP;
  int ALL = 0, fmx = 0, id = 0, smx = 0;
  if (DP == (n - sz[v]))
    ALL = DP;
  else
    fmx = DP;
  for (auto i : adj[v])
    if (i != par) {
      if (dp_down[i] == sz[i])
        ALL += sz[i];
      else if (fmx < dp_down[i]) {
        fmx = dp_down[i];
        id = i;
      }
    }
  for (auto i : adj[v])
    if (i != par && i != id)
      if (dp_down[i] != sz[i]) smx = max(smx, dp_down[i]);
  for (auto i : adj[v])
    if (i != par) {
      int go = ALL + fmx + 1;
      if (i == id) go -= fmx - smx;
      if (dp_down[i] == sz[i]) go -= sz[i];
      if (arr[v] < val) go = 0;
      dfs_up(i, val, v, go);
    }
  dp_down[v] = ALL + fmx + 1;
  if (arr[v] < val) dp_down[v] = 0;
  return;
}
bool check(int val) {
  dfs_down(1, val);
  dfs_up(1, val);
  for (int v = 1; v <= n; v++)
    if (dp_down[v] >= k) return true;
  return false;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> arr[i];
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  int lo = 1;
  int hi = 1e6 + 1;
  while ((hi - lo) > 1) {
    int mid = lo + hi >> 1;
    if (check(mid))
      lo = mid;
    else
      hi = mid;
  }
  cout << lo << '\n';
  return 0;
}
