#include <bits/stdc++.h>
using namespace std;
int n, K, w[201000], in[201000], q[201000], sz[201000], res;
vector<int> e[201000], g[201000];
bool vis[201000], avi[201000], umv[201000];
int dfs(int x) {
  vis[x] = true;
  int w0 = 0, w1 = 0;
  for (int v : g[x])
    if (!vis[v]) {
      int d = dfs(v);
      if (d > w0)
        w1 = w0, w0 = d;
      else if (d > w1)
        w1 = d;
    }
  res = max(res, w0 + w1 + sz[x]);
  return w0 + sz[x];
}
void del(int x) {
  vis[x] = true;
  int cc = 0;
  for (int v : e[x])
    if (!vis[v] && avi[v]) {
      --in[v], sz[v] += sz[x];
      ++cc;
      if (in[v] == 1 && !umv[v]) del(v);
    }
}
bool check(int _w) {
  for (int x = 1; x <= n; ++x) {
    avi[x] = (w[x] >= _w);
    if (avi[x]) sz[x] = 1, in[x] = 0, vis[x] = umv[x] = false;
  }
  for (int x = 1; x <= n; ++x) {
    if (avi[x])
      for (int v : e[x]) ++in[v];
    else
      for (int v : e[x]) umv[v] = true;
  }
  for (int x = 1; x <= n; ++x)
    if (in[x] == 1 && !umv[x] && avi[x] && !vis[x]) del(x);
  for (int x = 1; x <= n; ++x)
    if (!vis[x] && avi[x])
      for (int v : e[x])
        if (!vis[v] && avi[v]) g[x].push_back(v);
  res = 0;
  for (int x = 1; x <= n; ++x)
    if (!vis[x] && avi[x]) dfs(x);
  return res >= K;
}
int main() {
  scanf("%d%d", &n, &K);
  int t1, t2;
  for (int i = 1; i <= n; ++i) scanf("%d", &w[i]);
  for (int i = 1; i <= n - 1; ++i)
    scanf("%d%d", &t1, &t2), e[t1].push_back(t2), e[t2].push_back(t1);
  int l = 0, r = 1000010;
  for (; l < r;) {
    int mid = (l + r + 1) >> 1;
    if (check(mid))
      l = mid;
    else
      r = mid - 1;
  }
  printf("%d\n", l);
  return 0;
}
