#include <bits/stdc++.h>
using namespace std;
int n, k;
vector<int> near[200010];
int sz[200010], a[200010];
bool f = false;
int setsz(int now, int prv) {
  int &res = sz[now];
  for (int x : near[now])
    if (x - prv) res += setsz(x, now);
  return ++res;
}
pair<int, int> check(int now, int prv, int x) {
  int fix = 1;
  int wild1 = 0, wild2 = 0;
  int bench = 0, wildcnt = 0;
  for (int y : near[now]) {
    if (y - prv) {
      pair<int, int> temp = check(y, now, x);
      int v = temp.first;
      if (v == sz[y])
        fix += v;
      else {
        wildcnt++;
        if (v > wild1) {
          swap(wild1, wild2);
          wild1 = v;
          bench = temp.second;
        } else if (v > wild2)
          wild2 = v;
      }
    }
  }
  if (a[now] >= x) {
    if (wildcnt < 2) {
      f |= (fix + wild1 + bench >= k);
      return make_pair((fix + wild1), (bench));
    } else {
      f |= (fix + wild1 + wild2 >= k);
      return make_pair((fix + wild1), (wild2));
    }
  } else
    return make_pair((0), (0));
}
int bins(int l, int r) {
  int mid = (l + r) / 2;
  if (l > r) return r;
  f = false;
  check(1, 1, mid);
  if (f)
    return bins(mid + 1, r);
  else
    return bins(l, mid - 1);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    near[u].push_back(v);
    near[v].push_back(u);
  }
  sz[1] = setsz(1, 1);
  cout << bins(0, 1000000000) << endl;
  return 0;
}
