#include <bits/stdc++.h>
using namespace std;
int n, k, a[200005];
vector<int> adj[200005];
bool comp[200005];
int sum[200005];
pair<int, int> mx[2][200005];
pair<int, int> dfs(int x, int p, int z) {
  comp[x] = 1;
  pair<int, int> m;
  sum[x] = 1;
  for (int i = 0; i < adj[x].size(); ++i) {
    if (adj[x][i] == p) continue;
    m = dfs(adj[x][i], x, z);
    if (m.second)
      sum[x] += m.first;
    else {
      comp[x] = 0;
      m.second = adj[x][i];
      if (m > mx[0][x]) swap(m, mx[0][x]);
      if (m > mx[1][x]) swap(m, mx[1][x]);
    }
  }
  if (a[x] < z) {
    comp[x] = 0;
    sum[x] = 0;
    mx[0][x] = mx[1][x] = make_pair(-1, 0);
    return make_pair(0, 0);
  }
  if (comp[x]) return make_pair(sum[x], 1);
  return make_pair(sum[x] + mx[0][x].first, 0);
}
void dfs1(int x, int p, int z) {
  if (p && a[x] >= z) {
    if (!comp[p] && (mx[1][p].first != -1 || mx[0][p].second != x)) {
      pair<int, int> m;
      m = mx[0][p];
      if (m.second == x) m = mx[1][p];
      m.first += sum[p];
      if (comp[x]) m.first -= sum[x];
      m.second = p;
      if (m > mx[0][x]) swap(m, mx[0][x]);
      if (m > mx[1][x]) swap(m, mx[1][x]);
      comp[x] = 0;
    } else {
      if (!comp[x])
        sum[x] += sum[p];
      else
        sum[x] = sum[p];
    }
  }
  for (int i = 0; i < adj[x].size(); ++i)
    if (adj[x][i] != p) dfs1(adj[x][i], x, z);
}
bool check(int mid) {
  for (int i = 1; i <= n; ++i) {
    comp[i] = 0;
    sum[i] = 0;
    mx[0][i] = mx[1][i] = make_pair(-1, 0);
  }
  dfs(1, 0, mid);
  dfs1(1, 0, mid);
  for (int i = 1; i <= n; ++i)
    if (sum[i] + max(0, mx[0][i].first) >= k) return 1;
  return 0;
}
int main() {
  cin >> n >> k;
  int u, v;
  for (int i = 1; i <= n; ++i) scanf("%d", a + i);
  for (int i = 1; i < n; ++i) {
    scanf("%d%d", &u, &v);
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  int st = 0, en = 1e6 + 4, mid;
  while (st < en) {
    mid = (st + en) / 2;
    if (check(mid))
      st = mid + 1;
    else
      en = mid;
  }
  cout << st - 1 << endl;
}
