#include <bits/stdc++.h>
using namespace std;
int n, qwe;
int a[200005];
vector<int> g[200005];
set<int> w[200005];
bool b[200005];
int v[200005];
bool vis[200005];
int d[200005];
stack<int> st;
vector<int> c;
void dfs(int x, int f) {
  vis[x] = true;
  c.push_back(x);
  for (set<int>::iterator it = w[x].begin(); it != w[x].end(); ++it) {
    int y = *it;
    if (y == f) continue;
    d[y] = d[x] + v[y];
    dfs(y, x);
  }
}
int diam(int x) {
  c.clear();
  d[x] = v[x];
  dfs(x, -1);
  int y = x;
  for (int i = 1, to = c.size(); i < to; ++i) {
    if (d[c[i]] > d[y]) y = c[i];
  }
  d[y] = v[y];
  c.clear();
  dfs(y, -1);
  int r = 0;
  for (int i = 0, to = c.size(); i < to; ++i) r = max(r, d[c[i]]);
  return r;
}
bool can(int m) {
  for (int x = 0, to = n; x < to; ++x) w[x].clear();
  memset(b, false, sizeof(b));
  memset(v, 0, sizeof(v));
  for (int x = 0, to = n; x < to; ++x) {
    for (int i = 0, to = g[x].size(); i < to; ++i) {
      int y = g[x][i];
      if (a[x] < m || a[y] < m) {
        b[x] = b[y] = true;
      } else {
        w[x].insert(y);
        w[y].insert(x);
      }
    }
    if (a[x] >= m) v[x] = 1;
  }
  for (int x = 0, to = n; x < to; ++x) {
    if (!b[x] && w[x].size() == 1) st.push(x);
  }
  while (!st.empty()) {
    int x = st.top();
    st.pop();
    int y = *w[x].begin();
    w[x].erase(y);
    w[y].erase(x);
    v[y] += v[x];
    if (!b[y] && w[y].size() == 1) st.push(y);
  }
  memset(vis, false, sizeof(vis));
  int r = 0;
  for (int x = 0, to = n; x < to; ++x) {
    if (!vis[x]) r = max(r, diam(x));
  }
  return r >= qwe;
}
int main() {
  int k;
  scanf("%d%d", &n, &qwe);
  for (int i = 0, to = n; i < to; ++i) scanf("%d", a + i);
  for (int i = 1, to = n; i < to; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    x--;
    y--;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  int s = 1, e = 1000001;
  while (e - s > 1) {
    int m = (s + e) / 2;
    if (can(m))
      s = m;
    else
      e = m;
  }
  printf("%d\n", s);
  return 0;
}
