#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
const int MAXN = 1e6 + 10;
const long long MOD = 1e9 + 7;
const long long MOD2 = 998244353;
const long long INF = 8e18;
const int LOG = 22;
long long pw(long long a, long long b, long long mod) {
  return (!b ? 1
             : (b & 1 ? (a * pw(a * a % mod, b / 2, mod)) % mod
                      : pw(a * a % mod, b / 2, mod)));
}
int A[MAXN], mark[MAXN], sz[MAXN], OK[MAXN], dp[MAXN], n, k, ans;
vector<int> G[MAXN];
void pre(int v, int par) {
  sz[v] = 1;
  OK[v] = mark[v];
  for (auto u : G[v]) {
    if (u == par) continue;
    pre(u, v);
    sz[v] += sz[u];
    OK[v] += OK[u];
  }
}
void dfs_down(int v, int par) {
  dp[v] = 1;
  int Mx1 = 0;
  for (auto u : G[v]) {
    if (par == u) continue;
    dfs_down(u, v);
    if (sz[u] == OK[u]) {
      dp[v] += sz[u];
    } else {
      Mx1 = max(Mx1, dp[u]);
    }
  }
  dp[v] += Mx1;
  if (mark[v] == 0) {
    dp[v] = 0;
    return;
  }
}
void dfs_up(int v, int par, int parval = 0) {
  int sum = 0;
  if ((sz[1] - sz[v]) == (OK[1] - OK[v])) {
    sum += n - sz[v];
    parval = 0;
  }
  int Mx1 = parval, Mx2 = 0;
  vector<int> child;
  for (auto u : G[v]) {
    if (u == par) {
      continue;
    }
    if (sz[u] == OK[u]) {
      sum += sz[u];
    } else {
      child.push_back(u);
      if (Mx1 < dp[u]) {
        Mx2 = Mx1;
        Mx1 = dp[u];
      } else {
        Mx2 = max(Mx2, dp[u]);
      }
    }
  }
  if (mark[v] == 0) {
    for (auto u : child) {
      dfs_up(u, v, 0);
    }
    return;
  }
  ans = max({ans, dp[v], Mx1 + Mx2 + 1 + sum});
  for (auto u : child) {
    if (dp[u] == Mx1) {
      dfs_up(u, v, sum + Mx2 + 1);
    } else {
      dfs_up(u, v, sum + Mx1 + 1);
    }
  }
}
bool check(int x) {
  ans = 0;
  memset(dp, 0, sizeof dp);
  memset(OK, 0, sizeof OK);
  memset(sz, 0, sizeof sz);
  for (int i = 1; i <= n; i++) {
    mark[i] = (A[i] >= x);
  }
  pre(1, 0);
  dfs_down(1, 0);
  dfs_up(1, 0);
  for (int i = 1; i <= n; i++) {
    ans = max(ans, dp[i]);
  }
  return (ans >= k);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> A[i];
  }
  for (int i = 1; i < n; i++) {
    int a, b;
    cin >> a >> b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  int d = 0, up = 1e6 + 1;
  while (up - d > 1) {
    int mid = (up + d) >> 1;
    if (check(mid)) {
      d = mid;
    } else {
      up = mid;
    }
  }
  if (check(d + 1)) {
    d++;
  }
  cout << d << "\n";
  return 0;
}
