#include <bits/stdc++.h>
using namespace std;
const int MAXN = 212345;
vector<int> adj[MAXN];
int a[MAXN];
int n, k;
int st[MAXN];
int ed[MAXN];
int P[MAXN];
int order[MAXN];
int o_idx = 1;
void dfs(int node, int par) {
  P[node] = par;
  st[node] = o_idx;
  order[o_idx++] = node;
  for (int i = 0; i < (int)adj[node].size(); i++) {
    int v = adj[node][i];
    if (v != par) {
      dfs(v, node);
    }
  }
  ed[node] = o_idx - 1;
}
int memo[MAXN];
int hasZero[MAXN];
bool check(int mn) {
  memset(memo, 0, sizeof memo);
  memset(hasZero, 0, sizeof hasZero);
  bool ok = 0;
  for (int node_id = n; node_id > 0; node_id--) {
    int node = order[node_id];
    if (a[node] < mn) {
      memo[node] = 0;
      hasZero[node] = 1;
    } else {
      memo[node] = 1;
      vector<int> zeros;
      for (int i = 0; i < (int)adj[node].size(); i++) {
        int v = adj[node][i];
        if (v != P[node]) {
          if (hasZero[v]) {
            zeros.push_back(memo[v]);
            sort(zeros.rbegin(), zeros.rend());
            if (zeros.size() == 3) zeros.pop_back();
          } else {
            memo[node] += memo[v];
          }
        }
      }
      if (zeros.size()) {
        memo[node] += zeros[0];
        hasZero[node] = 1;
        if (zeros.size() == 2) {
          if (memo[node] + zeros[1] >= k) ok = 1;
        }
      }
      if (memo[node] >= k) ok = 1;
    }
  }
  return ok;
}
int solve() {
  int l = 1, r = 1000000;
  while (l <= r) {
    int md = (l + r) >> 1;
    if (check(md)) {
      l = md + 1;
    } else {
      r = md - 1;
    }
  }
  return l - 1;
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  int ans = 0;
  srand(time(0));
  for (int it = 0; it < 10; it++) {
    int r = rand() % n + 1;
    o_idx = 1;
    dfs(r, 0);
    ans = max(ans, solve());
  }
  printf("%d\n", ans);
}
