#include <bits/stdc++.h>
inline long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
inline void sub(long long &a, long long b) {
  a -= b;
  if (a < 0) a += 1000000007;
}
inline void add(long long &a, long long b) {
  a += b;
  if (a >= 1000000007) a -= 1000000007;
}
template <typename T>
inline T const &MAX(T const &a, T const &b) {
  return a > b ? a : b;
}
template <typename T>
inline T const &MIN(T const &a, T const &b) {
  return a < b ? a : b;
}
inline long long mul(long long a, long long b, long long c) {
  return (a * b - (long long)((long double)a * b / c) * c + c) % c;
}
inline long long qp(long long a, long long b) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans = ans * a % 1000000007;
    a = a * a % 1000000007, b >>= 1;
  }
  return ans;
}
inline long long qp(long long a, long long b, long long c) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans = mul(ans, a, c);
    a = mul(a, a, c), b >>= 1;
  }
  return ans;
}
using namespace std;
const unsigned long long ba = 233;
const double eps = 1e-5;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const int N = 200000 + 10, maxn = 2000000 + 10, inf = 0x3f3f3f3f;
vector<int> v[N];
bool ok;
int a[N], cnt[N], sz[N], n, k, dp[N], sum;
void dfs(int u, int f) {
  sz[u] = 1;
  for (int x : v[u])
    if (x != f) dfs(x, u), sz[u] += sz[x];
}
void dfs1(int u, int f, int m) {
  if (ok) return;
  dp[u] = cnt[u] = (a[u] >= m);
  int ma1 = 0, ma2 = 0;
  for (int x : v[u])
    if (x != f) {
      dfs1(x, u, m);
      cnt[u] += cnt[x];
      if (a[u] >= m) {
        if (dp[x] == sz[x])
          dp[u] += dp[x];
        else if (dp[x] >= ma1)
          ma2 = ma1, ma1 = dp[x];
        else if (dp[x] >= ma2)
          ma2 = dp[x];
      }
    }
  if (a[u] >= m) {
    dp[u] += ma1;
    int te = dp[u] + ma2;
    if (n - sz[u] == sum - cnt[u]) te += n - sz[u];
    if (te >= k) ok = 1;
  }
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i < n; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    v[a].push_back(b), v[b].push_back(a);
  }
  dfs(1, 1);
  int l = 0, r = 1000000;
  while (l < r - 1) {
    int m = (l + r) >> 1;
    sum = ok = 0;
    for (int i = 1; i <= n; i++) sum += (a[i] >= m);
    dfs1(1, 1, m);
    if (ok)
      l = m;
    else
      r = m;
  }
  printf("%d\n", l);
  return 0;
}
