#include <bits/stdc++.h>
using namespace std;
const int M = 200200;
int n, k, b;
vector<int> g[M];
int a[M];
int sub[M];
int ans;
void read() {
  cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  for (int i = 0; i < n - 1; ++i) {
    int u, v;
    cin >> u >> v;
    --u, --v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
}
int dfs(int v, int u) {
  int cur = 1;
  int mx1 = 0, mx2 = 0;
  sub[v] = 1;
  for (int to : g[v])
    if (to != u) {
      int x = dfs(to, v);
      sub[v] += sub[to];
      if (x == sub[to]) {
        cur += x;
      } else if (x > mx1) {
        mx2 = mx1;
        mx1 = x;
      } else if (x > mx2) {
        mx2 = x;
      }
    }
  if (a[v] >= b) {
    ans = max(ans, cur + mx1 + mx2);
    return cur + mx1;
  } else {
    return 0;
  }
}
void kill() {
  int l = 0, r = 1e6;
  int st = min_element(a, a + n) - a;
  while (l < r) {
    b = (l + r) / 2 + 1;
    ans = 0;
    dfs(st, n);
    if (ans >= k)
      l = b;
    else
      r = b - 1;
  }
  cout << l << endl;
}
int main() {
  cout.precision(20);
  cout << fixed;
  ios_base::sync_with_stdio(false);
  read();
  kill();
}
