#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n, k, a[N], t, b[N], p[N], dp[2][N];
vector<int> g[N], kd[N];
pair<int, int> dis[N];
bool c[N];
void dfs(const int &v, const int &w) {
  for (auto u : g[v]) {
    if (u != w) {
      p[u] = v;
      dis[u].first = dis[v].first + 1;
      dis[u].second = u;
      kd[v].push_back(u);
      dfs(u, v);
    }
  }
}
bool ok(const int &x) {
  int ans, y, v;
  t = 0;
  for (int i = 0; i < n; ++i) {
    if (a[i] < x) {
      ++t;
      b[i] = 1;
      c[i] = 1;
    } else {
      b[i] = 0;
      c[i] = 0;
    }
  }
  for (int i = n - 1; i >= 0; --i) {
    v = dis[i].second;
    for (auto u : kd[v]) b[v] += b[u];
    if (c[v]) {
      dp[0][v] = 0;
      continue;
    }
    dp[0][v] = 1;
    y = 0;
    for (auto u : kd[v]) {
      if (b[u] == 0)
        dp[0][v] += dp[0][u];
      else
        y = max(y, dp[0][u]);
    }
    dp[0][v] += y;
  }
  for (int i = 0; i < n; ++i) {
    v = dis[i].second;
    if (c[v]) {
      for (auto u : kd[v]) dp[1][u] = 0;
      continue;
    }
    ans = 1, y = n;
    for (auto u : kd[v]) {
      if (b[u] == 0)
        ans += dp[0][u];
      else if (dp[0][u] > dp[0][y])
        y = u;
    }
    ans += dp[0][y];
    if (b[v] == t)
      ans += dp[1][v];
    else if (dp[1][v] > dp[0][y]) {
      ans -= dp[0][y];
      y = v;
      ans += dp[1][y];
    }
    for (auto u : kd[v]) {
      if (c[u]) {
        dp[1][u] = 0;
        continue;
      }
      if (b[u] == 0)
        dp[1][u] = ans - dp[0][u];
      else if (u != y)
        dp[1][u] = ans;
      else {
        dp[1][u] = ans - dp[0][u];
        int z = 0;
        for (auto w : kd[v]) {
          if (w != u && b[w] != 0) z = max(z, dp[0][w]);
        }
        if (b[v] != t) z = max(z, dp[1][v]);
        dp[1][u] += z;
      }
    }
  }
  for (int i = 0; i < n; ++i) {
    if (c[i]) continue;
    ans = 1, y = 0;
    if (b[i] == t)
      ans += dp[1][i];
    else
      y = dp[1][i];
    for (auto w : kd[i]) {
      if (b[w] == 0)
        ans += dp[0][w];
      else
        y = max(y, dp[0][w]);
    }
    ans += y;
    if (ans >= k) return 1;
  }
  return 0;
}
int bin(const int &l, const int &r) {
  if (r - l == 1) return l;
  int m = (l + r) / 2;
  if (ok(m)) return bin(m, r);
  return bin(l, m);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  int w = 0;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    w = max(w, a[i]);
  }
  int u, v;
  for (int i = 1; i < n; ++i) {
    cin >> u >> v;
    g[--u].push_back(--v);
    g[v].push_back(u);
  }
  dfs(0, 0);
  sort(dis, dis + n);
  cout << bin(1, w + 1);
}
