#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 2;
vector<int> val, adj[N];
int sz[N], big[N], p[N], mm[N], mn[N], ok[N], a[N], ans[N], mx[N], found, n, k,
    lim;
void get(int u, int sum, int root) {
  if (a[u] < lim) return;
  if (2 + sum + mx[root] >= k) found = 1;
  for (int v : adj[u]) get(v, sum + 1 + ans[u] - ok[v] * (ans[v] + 1), root);
}
void add(int u, int sum, int root) {
  if (a[u] < lim) return;
  mx[root] = max(mx[root], sum + 1);
  for (int v : adj[u]) add(v, sum + ans[u] - ok[v] * (ans[v] + 1), root);
}
void dsu(int u) {
  if (found) return;
  for (int v : adj[u]) {
    if (v == big[u]) continue;
    dsu(v);
    if (ans[v] == sz[v] - 1 && a[v] >= lim)
      ok[v] = 1, ans[u] += ans[v] + 1;
    else
      ok[v] = 0;
  }
  if (big[u]) {
    dsu(big[u]);
    if (ans[big[u]] == sz[big[u]] - 1 && a[big[u]] >= lim)
      ok[big[u]] = 1, ans[u] += ans[big[u]] + 1;
    else
      ok[big[u]] = 0;
  }
  if (a[u] >= lim) {
    mx[u] = mx[big[u]] - ok[big[u]] * (ans[big[u]] + 1);
    if (mn[u] >= lim) ans[u] += (n - sz[u]);
    if (ans[u] + 1 >= k || 1 + ans[u] + mx[u] >= k) found = 1;
    for (int v : adj[u]) {
      if (v == big[u] || a[v] < lim) continue;
      if (mx[u] + ans[u] - ok[v] * (ans[v] + 1) + 1 + mx[v] >= k) found = 1;
      mx[u] = max(mx[u], mx[v] - ok[v] * (ans[v] + 1));
    }
    if (mn[u] >= lim) ans[u] -= (n - sz[u]);
    mx[u] += (ans[u] + 1);
  } else
    ans[u] = mx[u] = 0;
  if (mx[u] >= k) found = 1;
}
bool check() {
  found = 0;
  fill_n(ans, n + 1, 0);
  fill_n(mx, n + 1, 0);
  dsu(1);
  return found;
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  if (fopen("test"
            ".inp",
            "r")) {
    freopen(
        "test"
        ".inp",
        "r", stdin);
    freopen(
        "test"
        ".out",
        "w", stdout);
  }
  cin >> n >> k;
  for (int i = 1; i <= n; ++i) cin >> a[i], val.emplace_back(a[i]);
  sort(val.begin(), val.end());
  val.erase(unique(val.begin(), val.end()), val.end());
  if (k == 1) return cout << val.back(), 0;
  for (int u, v, i = 1; i < n; ++i) {
    cin >> u >> v;
    adj[u].emplace_back(v), adj[v].emplace_back(u);
  }
  function<void(int, int)> dfs = [&](int u, int par) {
    sz[u] = 1, big[u] = 0, p[u] = par;
    mm[u] = a[u];
    for (int& v : adj[u]) {
      if (v == par) swap(v, adj[u].back());
      if (v == par) continue;
      dfs(v, u);
      sz[u] += sz[v];
      mm[u] = min(mm[u], mm[v]);
      if (sz[big[u]] < sz[v]) big[u] = v;
    }
    if (par != -1) adj[u].pop_back();
  };
  mn[1] = 1e9;
  function<void(int)> minimize = [&](int u) {
    int tmp = min(a[u], mn[u]);
    for (int v : adj[u]) {
      mn[v] = tmp;
      tmp = min(tmp, mm[v]);
    }
    reverse(adj[u].begin(), adj[u].end());
    tmp = min(a[u], mn[u]);
    for (int v : adj[u]) {
      mn[v] = min(mn[v], tmp);
      tmp = min(tmp, mm[v]);
      minimize(v);
    }
  };
  dfs(1, -1), minimize(1);
  int low = 0, mid, high = val.size() - 1;
  while (low <= high) {
    mid = low + high >> 1;
    lim = val[mid];
    if (check())
      low = mid + 1;
    else
      high = mid - 1;
  }
  cout << val[high];
}
