#include <bits/stdc++.h>
using namespace std;
const int maxN = 2e5 + 13, INF = 1e7 + 13;
int dp[maxN], k, val[maxN], ans, node, n, sz[maxN];
vector<int> adj[maxN];
void dfs(int x, int par, int mn) {
  sz[x] = 1;
  dp[x] = 1;
  int mx1 = 0, mx2 = 0;
  for (auto a : adj[x]) {
    if (a != par) {
      dfs(a, x, mn);
      sz[x] += sz[a];
      if (dp[a] == sz[a])
        dp[x] += dp[a];
      else {
        if (dp[a] > mx1) {
          mx2 = mx1;
          mx1 = dp[a];
        } else
          mx2 = max(mx2, dp[a]);
      }
    }
  }
  if (val[x] < mn) {
    dp[x] = 0;
    return;
  }
  ans = max(ans, dp[x] + mx1 + mx2);
  dp[x] += mx1;
}
bool check(int val) {
  memset(dp, 0, sizeof dp);
  ans = 0;
  dfs(node, node, val);
  if (ans >= k) return 1;
  return 0;
}
int main() {
  cin >> n >> k;
  int mini = INF;
  for (int i = 0; i < n; i++) {
    cin >> val[i];
    if (val[i] < mini) {
      mini = val[i];
      node = i;
    }
  }
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  int l = 0, r = INF;
  while (r - l > 1) {
    int mid = l + r >> 1;
    if (check(mid))
      l = mid;
    else
      r = mid;
  }
  cout << l << endl;
}
