#include <bits/stdc++.h>
using namespace std;
const int N = 212345;
vector<int> g[N];
int menor[N], a[N], sz[N], dp[N];
int mid;
void dfs(int u, int pu) {
  menor[u] = a[u];
  sz[u] = 1;
  dp[u] = 1;
  int best = 0;
  for (auto v : g[u]) {
    if (v == pu) continue;
    dfs(v, u);
    menor[u] = min(menor[u], menor[v]);
    sz[u] += sz[v];
    if (menor[v] >= mid)
      dp[u] += sz[v];
    else
      best = max(best, dp[v]);
  }
  if (a[u] < mid)
    dp[u] = 0;
  else
    dp[u] += best;
}
int maior, n;
void solve(int u, int pu, int dp_c, int menor_c) {
  {
    int ans = 1;
    int best = 0;
    for (auto v : g[u]) {
      if (v == pu) continue;
      if (menor[v] >= mid)
        ans += sz[v];
      else
        best = max(best, dp[v]);
    }
    if (menor_c >= mid)
      ans += n - sz[u];
    else
      best = max(best, dp_c);
    if (a[u] >= mid)
      ans += best;
    else
      ans = 0;
    maior = max(maior, ans);
  }
  int tudo = 0;
  vector<pair<int, int> > a, b;
  for (auto v : g[u]) {
    if (v == pu) continue;
    if (menor[v] >= mid)
      tudo += sz[v];
    else
      a.emplace_back(dp[v], v);
    b.emplace_back(menor[v], v);
  }
  if (menor_c >= mid)
    tudo += n - sz[u];
  else
    a.emplace_back(dp_c, -1);
  b.emplace_back(menor_c, -1);
  {
    pair<int, int> x1, x2;
    if (a.size() > 0) {
      nth_element(a.begin(), a.begin(), a.end(), greater<pair<int, int> >());
      x1 = a[0];
    }
    if (a.size() > 1) {
      nth_element(a.begin(), a.begin() + 1, a.end(),
                  greater<pair<int, int> >());
      x2 = a[1];
    }
    if (a.size() > 0) a[0] = x1;
    if (a.size() > 1) a[1] = x2;
  }
  {
    pair<int, int> x1, x2;
    if (b.size() > 0) {
      nth_element(b.begin(), b.begin(), b.end());
      x1 = b[0];
    }
    if (b.size() > 1) {
      nth_element(b.begin(), b.begin() + 1, b.end());
      x2 = b[1];
    }
    if (b.size() > 0) b[0] = x1;
    if (b.size() > 1) b[1] = x2;
  }
  sort(b.begin(), b.end());
  menor_c = min(menor_c, ::a[u]);
  for (auto v : g[u]) {
    if (v == pu) continue;
    int ntudo = tudo;
    if (menor[v] >= mid) {
      ntudo -= sz[v];
      int new_cima = 1 + ntudo;
      int new_menor = menor_c;
      if (!a.empty()) new_cima += a[0].first;
      if (::a[u] < mid) new_cima = 0;
      if (b[0].second == v)
        new_menor = min(menor_c, b[1].first);
      else
        new_menor = min(menor_c, b[0].first);
      solve(v, u, new_cima, new_menor);
    } else {
      int new_cima = 1 + ntudo;
      int new_menor = menor_c;
      if (a[0].second != v)
        new_cima += a[0].first;
      else if (a.size() > 1)
        new_cima += a[1].first;
      if (::a[u] < mid) new_cima = 0;
      if (b[0].second == v)
        new_menor = min(menor_c, b[1].first);
      else
        new_menor = min(menor_c, b[0].first);
      solve(v, u, new_cima, new_menor);
    }
  }
}
int main(void) {
  int k;
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%d", a + i);
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    g[u].push_back(v);
    g[v].push_back(u);
  }
  int lo = 1, hi = 2000000, ans = -1;
  while (lo <= hi) {
    mid = (lo + hi) / 2;
    maior = 0;
    dfs(1, 0);
    solve(1, 0, 0, mid + 10);
    if (maior >= k) {
      ans = mid;
      lo = mid + 1;
    } else
      hi = mid - 1;
  }
  cout << ans << endl;
  return 0;
}
