#include <bits/stdc++.h>
using namespace std;
long long int Pow(long long int a, long long int b, long long int md,
                  long long int ans = 1) {
  for (; b; b >>= 1, a = a * a % md)
    if (b & 1) ans = ans * a % md;
  return ans % md;
}
const long long int MAXN = 2e5 + 10;
const long long int INF = 8e18;
const long long int MOD = 1e9 + 7;
long long int SZ[MAXN], dp[2][MAXN], A[MAXN], n, k, res = 0;
vector<long long int> adj[MAXN];
void merge(pair<long long int, long long int> &x, long long int y,
           long long int md) {
  if (y > x.second) x.second = y;
  if (x.second > x.first) swap(x.first, x.second);
}
void DFSsoroush(long long int v, long long int x, long long int p = -1) {
  SZ[v] = 1;
  long long int wot = 0;
  dp[0][v] = 1;
  for (long long int u : adj[v]) {
    if (u != p) {
      DFSsoroush(u, x, v);
      SZ[v] += SZ[u];
      if (dp[0][u] == SZ[u])
        dp[0][v] += SZ[u];
      else
        wot = max(wot, dp[0][u]);
    }
  }
  dp[0][v] += wot;
  if (A[v] < x) dp[0][v] = 0;
}
void DFSostad(long long int v, long long int x, long long int p = -1) {
  pair<long long int, long long int> mx = {0, 0};
  long long int t = (A[v] >= x);
  if (v != 1 && dp[1][v] == n - SZ[v])
    t += dp[1][v];
  else
    merge(mx, dp[1][v], x);
  for (long long int u : adj[v]) {
    if (u != p) {
      if (dp[0][u] == SZ[u]) {
        t += SZ[u];
      } else
        merge(mx, dp[0][u], x);
    }
  }
  if (A[v] < x)
    mx = {0, 0}, t = 0;
  else
    res = max(res, t + mx.first);
  for (long long int u : adj[v]) {
    if (u != p) {
      dp[1][u] = t + mx.first;
      if (dp[0][u] == SZ[u])
        dp[1][u] -= SZ[u];
      else if (dp[0][u] == mx.first) {
        dp[1][u] -= mx.first;
        dp[1][u] += mx.second;
      }
    }
  }
  for (long long int u : adj[v]) {
    if (u != p) DFSostad(u, x, v);
  }
}
long long int check(long long int x) {
  DFSsoroush(1, x);
  res = 0;
  DFSostad(1, x);
  return res >= k;
}
int main() {
  scanf("%lld%lld", &n, &k);
  for (long long int i = 1; i <= n; i++) scanf("%lld", &A[i]);
  for (long long int i = 1; i <= n - 1; i++) {
    long long int u, v;
    scanf("%lld%lld", &u, &v);
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  long long int l = 0, r = MOD;
  while (r - l > 1) {
    long long int mid = (l + r) >> 1;
    if (check(mid))
      l = mid;
    else
      r = mid;
  }
  printf("%lld\n", l);
  return 0;
}
