#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
vector<int> adj[maxn], nei[maxn];
int a[maxn], st[maxn], sz[maxn], sz2[maxn], mx1[maxn], mx2[maxn], v1[maxn],
    v2[maxn], dw[maxn], up[maxn];
int n, k, c, tim = 0, mx = 0;
bool mark[maxn];
void dfs(int v, int p = -1) {
  st[v] = tim++;
  sz[v] = 1;
  for (int u : adj[v]) {
    if (u != p) {
      dfs(u, v);
      sz[v] += sz[u];
    }
  }
}
void dfs2(int v) {
  mark[v] = true;
  sz2[v] = 1;
  dw[v] = up[v] = 1;
  c++;
  for (int u : nei[v]) {
    if (!mark[u]) {
      dfs2(u);
      sz2[v] += sz2[u];
      if (sz2[u] == sz[u]) {
        dw[v] += dw[u];
        up[v] += dw[u];
      } else {
        if (dw[u] >= mx1[v]) {
          mx2[v] = mx1[v];
          v2[v] = v1[v];
          mx1[v] = dw[u];
          v1[v] = u;
        } else if (dw[u] > mx2[v]) {
          mx2[v] = dw[u];
          v2[v] = u;
        }
      }
    }
  }
  dw[v] += mx1[v];
}
void dfs3(int v, int p = -1) {
  for (int u : nei[v]) {
    if (u != p) {
      if (n - sz[u] == c - sz2[u]) {
        up[u] = dw[u] + (n - sz[u]);
      } else {
        int val =
            -(u == v1[v] ? dw[u] - mx2[v] : 0) - (sz[u] == sz2[u] ? dw[u] : 0);
        if (n - sz[v] == c - sz2[v]) {
          up[u] += max(up[v], dw[v]) + val;
        } else {
          up[u] += max(up[v] - (sz[u] == sz2[u] ? dw[u] : 0), dw[v] + val);
        }
      }
      dfs3(u, v);
    }
  }
  mx = max({mx, up[v], dw[v]});
}
bool check(int x) {
  vector<pair<int, int> > vec;
  mx = 0;
  for (int i = 0; i < n; i++) {
    nei[i].clear();
    up[i] = dw[i] = mx1[i] = mx2[i] = mark[i] = mx = 0;
    v1[i] = v2[i] = -1;
  }
  for (int i = 0; i < n; i++) {
    if (a[i] >= x) {
      for (int u : adj[i]) {
        if (a[u] >= x) {
          nei[i].push_back(u);
        }
      }
      vec.push_back({st[i], i});
    }
  }
  sort(vec.begin(), vec.end());
  for (auto u : vec) {
    if (!mark[u.second]) {
      c = 0;
      dfs2(u.second);
      if (n - sz[u.second] == c - sz2[u.second]) {
        up[u.second] = dw[u.second];
      }
      dfs3(u.second);
    }
  }
  return (mx >= k);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n - 1; i++) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  dfs(0);
  int l = 0, r = 1e9;
  while (l + 1 < r) {
    int mid = (l + r) / 2;
    if (check(mid)) {
      l = mid;
    } else {
      r = mid;
    }
  }
  cout << l << endl;
  return 0;
}
