#include <bits/stdc++.h>
using namespace std;
const int inf = (int)1.01e9;
const double eps = 1e-9;
const int N = 2e5 + 10;
vector<int> v[N];
int a[N];
int b[N];
int n;
int w[N], d[N];
int f[N];
int res;
void dfs(int x) {
  f[x] = w[x];
  vector<int> vv;
  for (int i = 0; (i) < (((int)(v[x]).size())); ++i) {
    int y = v[x][i];
    if (w[y] && b[y] && !f[y]) {
      dfs(y);
      f[x] = max(f[x], f[y] + w[x]);
      vv.push_back(f[y]);
    }
  }
  sort((vv).begin(), vv.end());
  reverse((vv).begin(), vv.end());
  if (((int)(vv).size()) >= 2) res = max(res, w[x] + vv[0] + vv[1]);
  res = max(res, f[x]);
}
int calc(int T) {
  for (int i = 0; (i) < (n); ++i) b[i] = a[i] >= T;
  for (int i = 0; (i) < (n); ++i) d[i] = ((int)(v[i]).size());
  for (int i = 0; (i) < (n); ++i) w[i] = 1;
  set<pair<int, int> > second;
  for (int i = 0; (i) < (n); ++i) second.insert(make_pair(d[i], i));
  for (int _ = 0; (_) < (n); ++_) {
    int x = second.begin()->second;
    second.erase(second.begin());
    if (d[x] != 1) {
      break;
    }
    int to = -1;
    for (int i = 0; (i) < (((int)(v[x]).size())); ++i) {
      int y = v[x][i];
      if (w[y]) {
        to = y;
        break;
      }
    }
    if (b[x] && b[to]) {
      second.erase(make_pair(d[to], to));
      d[to] -= 1;
      w[to] += w[x];
      w[x] = 0;
      second.insert(make_pair(d[to], to));
    }
  }
  for (int i = 0; (i) < (n); ++i) f[i] = 0;
  res = 0;
  for (int i = 0; (i) < (n); ++i)
    if (b[i] && w[i] && !f[i]) {
      dfs(i);
    }
  return res;
}
int main() {
  int k;
  scanf("%d%d", &n, &k);
  for (int i = 0; (i) < (n); ++i) scanf("%d", a + i);
  for (int i = 0; (i) < (n - 1); ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    --x, --y;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  int l = 0, r = 1e6;
  while (l < r) {
    int m = (l + r + 1) >> 1;
    if (calc(m) >= k)
      l = m;
    else
      r = m - 1;
  }
  printf("%d\n", l);
  return 0;
}
