#include <bits/stdc++.h>
using namespace std;
char _;
const int maxN = 200 * 1000 + 5;
const int maxM = 5000 + 5;
const int mod = 1000 * 1000 * 1000 + 7;
const int base = 701;
const int SQ = 500;
const int maxL = 20;
int val[maxN];
vector<int> a[maxN];
int h[maxN], sz[maxN], ss[maxN];
int V, S;
int dp[maxN], D[maxN];
bool gg(int v) { return (sz[v] == 0); }
void dfs(int v, int par = -1) {
  sz[v] = (val[v] < V);
  ss[v] = 1;
  dp[v] = 0;
  int bes = 0;
  for (auto u : a[v])
    if (u - par) {
      h[u] = h[v] + 1;
      dfs(u, v);
      sz[v] += sz[u];
      ss[v] += ss[u];
      if (gg(u))
        dp[v] += ss[u];
      else
        bes = max(bes, dp[u]);
    }
  dp[v] += bes;
  if (val[v] < V)
    dp[v] = 0;
  else
    dp[v]++;
}
int n;
void DFS(int v, int par = -1) {
  int sum = 0;
  vector<pair<int, int> > pp;
  if (sz[v] == S)
    sum += (n - ss[v]);
  else
    pp.push_back({D[v], -1});
  for (auto u : a[v])
    if (u - par)
      if (gg(u))
        sum += ss[u];
      else {
        pp.push_back({dp[u], u});
        sort(pp.rbegin(), pp.rend());
        if (pp.size() > 2) pp.pop_back();
      }
  sum++;
  for (auto u : a[v])
    if (u - par) {
      if (val[v] >= V) {
        int tmp = sum;
        if (gg(u)) tmp -= ss[u];
        for (int i = 0; i < (int)pp.size(); i++)
          if (pp[i].second != u) {
            tmp += pp[i].first;
            break;
          }
        D[u] = tmp;
      } else
        D[u] = 0;
      DFS(u, v);
    }
}
int k;
bool check(int t) {
  V = t;
  S = 0;
  for (int i = 0; i < n; i++) S += (val[i] < V);
  dfs(0);
  DFS(0);
  for (int i = 0; i < n; i++) {
    if (val[i] < V) continue;
    int ans = 1;
    int bes = 0;
    for (auto u : a[i])
      if (h[u] > h[i]) {
        if (gg(u))
          ans += ss[u];
        else
          bes = max(bes, dp[u]);
      } else {
        if (sz[i] == S)
          ans += (n - ss[i]);
        else
          bes = max(bes, D[i]);
      }
    if (ans + bes >= k) return true;
  }
  return false;
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> val[i];
  for (int i = 1; i < n; i++) {
    int v, u;
    cin >> v >> u;
    v--;
    u--;
    a[v].push_back(u);
    a[u].push_back(v);
  }
  int lo = 0, hi = 1000 * 1000 + 5;
  while (hi - lo > 1) {
    int mid = (hi + lo) >> 1;
    if (check(mid))
      lo = mid;
    else
      hi = mid;
  }
  cout << lo << endl;
  return 0;
}
