#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
template <class T1, class T2>
inline void remin(T1& a, T2 b) {
  a = min(a, (T1)b);
}
const int maxN = 1 << 18, maxTS = maxN * 2, INF = 1 << 30;
vector<int> G[maxN];
int A[maxN], pat[maxN], whole[maxN], ile[maxN], sz[maxN], res, bord;
void dfs0(int v, int fat) {
  sz[v] = 1;
  ile[v] = A[v] >= bord;
  for (int u : G[v])
    if (u != fat) {
      dfs0(u, v);
      sz[v] += sz[u];
      ile[v] += ile[u];
    }
}
void dfs(int v, int fat) {
  int t[2] = {0, 0};
  whole[v] = pat[v] = 1;
  for (int u : G[v])
    if (u != fat) {
      dfs(u, v);
      if (whole[u] != 0) {
        if (whole[v] != 0) whole[v] += whole[u];
        pat[v] += whole[u];
        continue;
      }
      whole[v] = 0;
      if (pat[u] >= t[0])
        t[1] = t[0], t[0] = pat[u];
      else if (pat[u] > t[1])
        t[1] = pat[u];
    }
  if (A[v] >= bord) {
    pat[v] += t[0];
    int prop = pat[v] + t[1];
    if (sz[1] - sz[v] == ile[1] - ile[v]) prop += sz[1] - sz[v];
    res = max(res, prop);
  } else
    pat[v] = whole[v] = 0;
}
void solve() {
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = (1); i < (n + 1); i++) scanf("%d", A + i);
  for (int i = (1); i < (n); i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    G[a].push_back(b);
    G[b].push_back(a);
  }
  int a = 1, b = INF;
  while (b - a > 1) {
    bord = (a + b) / 2;
    res = 0;
    dfs0(1, 0);
    dfs(1, 0);
    res >= k ? a = bord : b = bord;
  }
  printf("%d\n", a);
}
int main() {
  int t = 1;
  for (int tid = (1); tid < (t + 1); tid++) {
    solve();
  }
  return 0;
}
