#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
template <class T>
inline void Max(T &a, T b) {
  if (a < b) a = b;
}
template <class T>
inline void Min(T &a, T b) {
  if (a > b) a = b;
}
inline void add(int &a, int b) {
  a += b;
  while (a >= 1000000007) a -= 1000000007;
}
int pow(int a, int b) {
  int ans = 1;
  while (b) {
    if (b & 1) ans = 1LL * ans * a % 1000000007;
    a = 1LL * a * a % 1000000007;
    b >>= 1;
  }
  return ans;
}
vector<int> g[200010];
int K, a[200010], n, lim, dp[200010], v[200010], sz[200010];
pair<int, int> f[200010][2];
int dfs(int u, int fa) {
  dp[u] = v[u] = 0;
  f[u][0] = f[u][1] = make_pair(0, u);
  if (a[u] < lim && sz[u] - 1 < K) {
    return 0;
  }
  for (int i = 0; i < g[u].size(); i++) {
    int j = g[u][i];
    if (j == fa) continue;
    if (dfs(j, u)) return 1;
  }
  if (a[u] < lim) {
    return 0;
  }
  for (int i = 0; i < g[u].size(); i++) {
    int j = g[u][i];
    if (j == fa) continue;
    if (a[j] < lim) continue;
    if (v[j]) {
      dp[u] += sz[j];
    } else if (f[u][0].first < f[j][0].first + dp[j] + 1) {
      f[u][1] = f[u][0];
      f[u][0] = make_pair(f[j][0].first + dp[j] + 1, j);
    } else if (f[u][1].first < f[j][0].first + dp[j] + 1)
      f[u][1] = make_pair(f[j][0].first + dp[j] + 1, j);
  }
  if (dp[u] == sz[u] - 1) {
    v[u] = 1;
  }
  if (dp[u] + 1 + f[u][0].first >= K) return 1;
  return 0;
}
int go(int u, int fa, int first, int second) {
  if (a[u] >= lim) {
    if (first == n - sz[u]) {
      if (first + 1 + dp[u] + f[u][0].first >= K) return 1;
    } else {
      if (dp[u] + 1 + max(first + second, f[u][0].first) >= K) return 1;
    }
  }
  if (a[u] < lim && sz[u] - 1 < K) return 0;
  for (int i = 0; i < g[u].size(); i++) {
    int j = g[u][i];
    if (j == fa) continue;
    if (a[u] < lim || a[j] < lim) {
      if (go(j, u, 0, 0)) return 1;
      continue;
    }
    if (v[j]) {
      if (first == n - sz[u]) {
        if (go(j, u, first + dp[u] - sz[j] + 1, f[u][0].first)) return 1;
      } else {
        if (go(j, u, dp[u] - sz[j] + 1, max(f[u][0].first, first + second)))
          return 1;
      }
    } else if (j == f[u][0].second) {
      if (first == n - sz[u]) {
        if (go(j, u, first + dp[u] + 1, f[u][1].first)) return 1;
      } else {
        if (go(j, u, dp[u] + 1, max(f[u][1].first, first + second))) return 1;
      }
    } else {
      if (first == n - sz[u]) {
        if (go(j, u, first + dp[u] + 1, f[u][0].first)) return 1;
      } else {
        if (go(j, u, dp[u] + 1, max(f[u][0].first, first + second))) return 1;
      }
    }
  }
  return 0;
}
int solve(int m) {
  lim = m;
  if (dfs(1, 0)) return 1;
  if (go(1, 0, 0, 0)) return 1;
  return 0;
}
void dfs1(int u, int fa) {
  sz[u] = 1;
  for (int i = 0; i < g[u].size(); i++) {
    int j = g[u][i];
    if (j == fa) continue;
    dfs1(j, u);
    sz[u] += sz[j];
  }
}
int main() {
  int i, j, k, T, m;
  scanf("%d%d", &n, &K);
  for (i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (i = 1; i < n; i++) {
    scanf("%d%d", &j, &k);
    g[j].push_back(k), g[k].push_back(j);
  }
  dfs1(1, 0);
  int l = 1, r = 1000000;
  while (l <= r) {
    m = (l + r) >> 1;
    if (solve(m))
      l = m + 1;
    else
      r = m - 1;
  }
  printf("%d\n", l - 1);
  return 0;
}
