#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int f = 1, ans = 0;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    ans = ans * 10 + c - '0';
    c = getchar();
  }
  return f * ans;
}
const int MAXN = 2e5 + 11;
int N, K, W[MAXN], Lim, A[MAXN], f[MAXN], Siz[MAXN], siz[MAXN];
vector<int> vec[MAXN];
void dfs(int u, int fath) {
  Siz[u] = (A[u]), siz[u] = 1;
  int Maxn = 0;
  for (auto v : vec[u]) {
    if (v == fath) continue;
    dfs(v, u);
    Siz[u] += Siz[v], siz[u] += siz[v];
    if (A[u]) {
      if (Siz[v] == siz[v])
        f[u] += siz[v];
      else
        Maxn = max(Maxn, f[v]);
    }
  }
  if (A[u]) f[u] += Maxn + 1;
  return;
}
bool ff;
void dfs1(int u, int fath) {
  int t = siz[u];
  siz[u] = N;
  if (A[u]) {
    int Maxn = 0, Ans = 0;
    for (auto v : vec[u]) {
      if (Siz[v] == siz[v])
        Ans += siz[v];
      else
        Maxn = max(Maxn, f[v]);
    }
    f[u] = Maxn + Ans + 1;
    if (Maxn + Ans + 1 >= K) ff = 1;
  }
  int s = f[u];
  int Maxn1 = 0, Maxn2 = 0;
  for (auto v : vec[u]) {
    if (Siz[v] != siz[v]) {
      if (f[v] >= Maxn1)
        Maxn2 = Maxn1, Maxn1 = f[v];
      else if (f[v] > Maxn2)
        Maxn2 = f[v];
    }
  }
  for (auto v : vec[u]) {
    if (v == fath) continue;
    siz[u] -= siz[v];
    if (!A[u]) {
      Siz[u] -= Siz[v];
      Siz[v] += Siz[u];
      dfs1(v, u);
      Siz[v] -= Siz[u];
      Siz[u] += Siz[v];
    } else if (siz[v] == Siz[v] && A[u]) {
      Siz[u] -= Siz[v];
      f[u] -= siz[v];
      Siz[v] += Siz[u];
      dfs1(v, u);
      f[u] += siz[v];
      Siz[v] -= Siz[u];
      Siz[u] += Siz[v];
    } else {
      if (f[v] == Maxn1) {
        f[u] -= Maxn1;
        f[u] += Maxn2;
        Siz[u] -= Siz[v];
        Siz[v] += Siz[u];
        dfs1(v, u);
        Siz[v] -= Siz[u];
        f[u] += Maxn1;
        f[u] -= Maxn2;
        Siz[u] += Siz[v];
      } else {
        Siz[u] -= Siz[v];
        Siz[v] += Siz[u];
        dfs1(v, u);
        Siz[v] -= Siz[u];
        Siz[u] += Siz[v];
      }
    }
    siz[u] += siz[v];
  }
  siz[u] = t;
  return;
}
bool check() {
  ff = 0;
  for (int i = 1; i <= N; i++) A[i] = (W[i] >= Lim);
  memset(siz, 0, sizeof(siz)), memset(f, 0, sizeof(f)),
      memset(Siz, 0, sizeof(Siz));
  dfs(1, 0);
  dfs1(1, 0);
  return ff;
}
int main() {
  N = read(), K = read();
  for (int i = 1; i <= N; i++) W[i] = read();
  for (int i = 1; i < N; i++) {
    int u = read(), v = read();
    vec[u].push_back(v), vec[v].push_back(u);
  }
  int l = 1, r = 1e6, res = -1;
  while (l <= r) {
    int mid = (l + r) >> 1;
    Lim = mid;
    if (check())
      res = mid, l = mid + 1;
    else
      r = mid - 1;
  }
  printf("%d\n", res);
  return 0;
}
