#include <bits/stdc++.h>
using namespace std;
vector<int> mat[200010];
int mina[200010], val[200010], use[200010], pa[200010];
pair<int, int> sz[200010];
int n, k;
int rec(int p, int pa, int v) {
  int ret = 0;
  mina[p] = val[p];
  for (auto x : mat[p])
    if (x != pa) ret = max(ret, rec(x, p, v)), mina[p] = min(mina[p], mina[x]);
  use[p] = 0;
  int mx1 = 0, mx2 = 0;
  for (auto x : mat[p]) {
    if (x == pa)
      continue;
    else if (mina[x] < v) {
      if (use[x] > mx1)
        mx2 = mx1, mx1 = use[x];
      else
        mx2 = max(mx2, use[x]);
    } else
      use[p] += use[x];
  }
  use[p] += mx1;
  sz[p].first = mx1;
  sz[p].second = mx2;
  if (val[p] >= v)
    use[p] += 1;
  else
    use[p] = 0, sz[p] = {0, 0};
  if (use[p] + sz[p].second >= k) ret = 1;
  return ret;
}
int dfs(int p, int pa, int v, int up, int ok) {
  int ret = 0;
  if (use[p] + up >= k && val[p] >= v) ret = 1;
  int fuka = up, faka = up, cnt = 0;
  if (sz[p].first > up) fuka = sz[p].first + ok * up;
  if (sz[p].second > up) faka = sz[p].second + ok * up;
  for (auto x : mat[p]) {
    if (x != pa && mina[x] >= v)
      fuka += use[x], faka += use[x];
    else if (x != pa)
      cnt++;
  }
  if (cnt != 1) ok = 0;
  if (val[p] >= v) faka++, fuka++;
  for (auto x : mat[p]) {
    if (x == pa) continue;
    if (val[p] < v)
      ret = max(ret, dfs(x, p, v, 0, 1));
    else if (mina[x] >= v)
      continue;
    else if (sz[p].first != use[x])
      ret = max(ret, dfs(x, p, v, fuka, ok));
    else
      ret = max(ret, dfs(x, p, v, faka, ok));
  }
  return ret;
}
int main() {
  ios::sync_with_stdio(false);
  int x, y;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> val[i];
  for (int i = 1; i <= n - 1; i++) {
    cin >> x >> y;
    mat[x].push_back(y);
    mat[y].push_back(x);
  }
  int st = 0, en = 1000000, mid;
  while (st <= en) {
    int mid = (st + en) >> 1;
    if (rec(1, 1, mid) || dfs(1, 1, mid, 0, 1))
      st = mid + 1;
    else
      en = mid - 1;
  }
  cout << st - 1 << endl;
  return 0;
}
