#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T bigmod(T p, T e, T M) {
  long long ret = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1) ret = (ret * p) % M;
    p = (p * p) % M;
  }
  return (T)ret;
}
template <class T>
inline T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <class T>
inline T modinverse(T a, T M) {
  return bigmod(a, M - 2, M);
}
vector<int> vc[200001];
int ar[200001], K;
int sz[200001], on[200001];
int dp[200001][2], mx, n;
void dfs1(int c, int p) {
  sz[c] = 1;
  for (int i = (0); i < (vc[c].size()); ++i) {
    if (vc[c][i] == p) continue;
    dfs1(vc[c][i], c);
    sz[c] += sz[vc[c][i]];
  }
}
void dfs(int m, int c, int p) {
  dp[c][0] = dp[c][1] = 0;
  for (int i = (0); i < (vc[c].size()); ++i) {
    if (vc[c][i] == p) continue;
    dfs(m, vc[c][i], c);
    if (sz[vc[c][i]] == dp[vc[c][i]][0])
      dp[c][0] += dp[vc[c][i]][0];
    else
      dp[c][1] = max(dp[c][1], dp[vc[c][i]][1]);
  }
  if (ar[c] < m) {
    on[c] = 0;
    dp[c][0] = dp[c][1] = 0;
  } else {
    on[c] = 1;
    dp[c][0]++;
    dp[c][1] += dp[c][0];
  }
}
int chk = 0;
void go(int c, int p, int d0, int d1, int tot) {
  int mxx1 = 0, mxx2 = 0, mxx3 = 0;
  if (d0 == tot)
    mxx1 += d0;
  else {
    if (d1 > mxx2) {
      mxx3 = mxx2;
      mxx2 = d1;
    } else if (d1 > mxx3) {
      mxx3 = d1;
    }
  }
  for (int i = (0); i < (vc[c].size()); ++i) {
    if (vc[c][i] == p) continue;
    if (sz[vc[c][i]] == dp[vc[c][i]][0])
      mxx1 += dp[vc[c][i]][0];
    else {
      if (dp[vc[c][i]][1] > mxx2) {
        mxx3 = mxx2;
        mxx2 = dp[vc[c][i]][1];
      } else if (dp[vc[c][i]][1] > mxx3) {
        mxx3 = dp[vc[c][i]][1];
      }
    }
  }
  tot = n;
  if (on[c]) {
    mxx1++;
    mxx2 += mxx1;
    mxx3 += mxx1;
    mx = max(mx, mxx2);
  } else {
    mxx1 = mxx2 = 0;
    for (int i = (0); i < (vc[c].size()); ++i) {
      if (vc[c][i] == p) continue;
      go(vc[c][i], c, 0, 0, tot - sz[vc[c][i]]);
    }
    return;
  }
  for (int i = (0); i < (vc[c].size()); ++i) {
    if (vc[c][i] == p) continue;
    if (sz[vc[c][i]] == dp[vc[c][i]][0])
      go(vc[c][i], c, mxx1 - dp[vc[c][i]][0], mxx2 - dp[vc[c][i]][0],
         tot - sz[vc[c][i]]);
    else if (mxx2 - mxx1 == dp[vc[c][i]][1])
      go(vc[c][i], c, mxx1, mxx3, tot - sz[vc[c][i]]);
    else
      go(vc[c][i], c, mxx1, mxx2, tot - sz[vc[c][i]]);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> K;
  for (int i = (1); i < (n + 1); ++i) cin >> ar[i];
  for (int i = (0); i < (n - 1); ++i) {
    int x, y;
    cin >> x >> y;
    vc[x].push_back(y);
    vc[y].push_back(x);
  }
  dfs1(1, 0);
  int lo = 1, hi = 1000000, mid = (lo + hi) / 2;
  while (lo < mid) {
    memset(on, 0, sizeof on);
    dfs(mid, 1, 0);
    mx = 0;
    go(1, 0, 0, 0, 0);
    if (mx >= K)
      lo = mid;
    else
      hi = mid - 1;
    mid = (lo + hi) / 2;
  }
  memset(on, 0, sizeof on);
  dfs(mid + 1, 1, 0);
  mx = 0;
  go(1, 0, 0, 0, 0);
  if (mx >= K) mid++;
  cout << mid << endl;
}
