#include <bits/stdc++.h>
using namespace std;
template <typename T>
T getint() {
  T x = 0, p = 1;
  char ch;
  do {
    ch = getchar();
  } while (ch <= ' ');
  if (ch == '-') p = -1, ch = getchar();
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  return x * p;
}
template <typename T1, typename T2>
bool umin(T1 &x, const T2 &y) {
  if (x > y) return x = y, true;
  return false;
}
template <typename T1, typename T2>
bool umax(T1 &x, const T2 &y) {
  if (x < y) return x = y, true;
  return false;
}
const int maxn = (int)1e6 + 100;
const int inf = (int)1e9 + 5;
const long long llinf = (long long)1e18 - 1;
const long double pi = acos(-1.0);
vector<int> g[maxn];
int dp[maxn];
int up[maxn];
int sz[maxn];
int a[maxn];
int satsum[maxn];
void calcs(int v, int p = -1) {
  sz[v] = 1;
  for (int x : g[v]) {
    if (x != p) {
      calcs(x, v);
      sz[v] += sz[x];
    }
  }
  if (p != -1) g[v].erase(find((g[v]).begin(), (g[v]).end(), p));
}
int lim, n, k;
void dfs(int v) {
  for (int x : g[v]) {
    dfs(x);
    if (dp[x] == sz[x]) satsum[v] += dp[x];
  }
  if (a[v] < lim) return;
  int best = 0;
  for (int x : g[v]) {
    if (dp[x] != sz[x]) best = max(best, dp[x]);
  }
  dp[v] = satsum[v] + best + 1;
}
void calcup(int v, int par = -1, pair<int, int> fmax = make_pair(-1, -1),
            pair<int, int> smax = make_pair(-1, -1)) {
  if (par != -1 && a[v] >= lim) {
    if (up[par] == -inf) {
      up[v] = 0;
    } else {
      int best = 0;
      if (n - sz[par] == up[par])
        up[v] += up[par];
      else
        umax(best, up[par]);
      up[v] += satsum[par] - (dp[v] == sz[v] ? sz[v] : 0);
      if (fmax.second != v) umax(best, fmax.first);
      if (smax.second != v) umax(best, smax.first);
      up[v] += best + 1;
    }
  } else if (a[v] < lim)
    up[v] = -inf;
  pair<int, int> a = make_pair(-1, -1), b = make_pair(-1, -1);
  for (int x : g[v]) {
    if (dp[x] == sz[x]) continue;
    if (dp[x] > a.first) {
      b = a;
      a = make_pair(dp[x], x);
    } else if (dp[x] > b.first) {
      b = make_pair(dp[x], x);
    }
  }
  for (int x : g[v]) calcup(x, v, a, b);
}
int solve(int x) {
  memset(dp, 0, sizeof dp);
  memset(up, 0, sizeof up);
  memset(satsum, 0, sizeof satsum);
  lim = x;
  dfs(0);
  calcup(0);
  int ret = 0;
  for (int i = (0); i < (n); i++) {
    ret = max(ret, dp[i] + up[i]);
  }
  return ret;
}
int main() {
  n = getint<int>();
  k = getint<int>();
  for (int i = (0); i < (n); i++) a[i] = getint<int>();
  for (int i = (0); i < (n - 1); i++) {
    int x = getint<int>() - 1;
    int y = getint<int>() - 1;
    g[x].push_back(y), g[y].push_back(x);
  }
  calcs(0);
  vector<int> z(a, a + n);
  sort((z).begin(), (z).end());
  int l = 0, r = n;
  while (r - l > 1) {
    int m = (l + r) / 2;
    if (solve(z[m]) >= k) {
      l = m;
    } else {
      r = m;
    }
  }
  printf("%d\n", z[l]);
  return 0;
}
