#include <bits/stdc++.h>
using namespace std;
int mv, m;
bool ccs[1123456];
int sz[1123456];
int dp[1123456], sp[1123456], tp[1123456];
int n;
vector<int> adj[1123456], child[1123456];
int a[1123456];
inline void dfs(int u, int p) {
  int v;
  int s = 1;
  sz[u] = 1;
  child[u].clear();
  for (int i = 0; i < adj[u].size(); ++i) {
    v = adj[u][i];
    if (v != p) {
      dfs(v, u);
      sz[u] += sz[v];
      if (ccs[v] == true) {
        s += sz[v];
      } else {
        child[u].push_back(v);
      }
    }
  }
  ccs[u] = false;
  sp[u] = 0;
  dp[u] = 0;
  tp[u] = 0;
  if (a[u] < m) {
    return;
  }
  if (child[u].size() == 0) {
    ccs[u] = true;
    sp[u] = s;
    dp[u] = s;
    tp[u] = s;
    mv = max(mv, s);
    return;
  }
  ccs[u] = false;
  if (child[u].size() == 1) {
    v = child[u][0];
    sp[u] = s + sp[v];
    dp[u] = s + sp[v];
    tp[u] = s + max(tp[v], dp[v]);
    mv = max(mv, sp[u]);
    mv = max(mv, dp[u]);
    mv = max(mv, tp[u]);
    return;
  }
  vector<int> vec;
  for (int i = 0; i < child[u].size(); ++i) {
    v = child[u][i];
    vec.push_back(sp[v]);
  }
  sort(vec.begin(), vec.end());
  int x = vec.size();
  sp[u] = s + vec[x - 1];
  dp[u] = s + vec[x - 1] + vec[x - 2];
  mv = max(mv, dp[u]);
  mv = max(mv, sp[u]);
  mv = max(mv, tp[u]);
}
int main() {
  int k, u, v;
  scanf("%d", &n);
  scanf("%d", &k);
  for (int i = 1; i < n + 1; ++i) {
    scanf("%d", &a[i]);
  }
  for (int i = 1; i < n; ++i) {
    scanf("%d", &u);
    scanf("%d", &v);
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  int l = 1, r = 10000000;
  while (l < r) {
    m = (l + r) / 2 + 1;
    mv = 0;
    dfs(1, 0);
    if (mv >= k) {
      l = m;
    } else {
      r = m - 1;
    }
  }
  cout << l << endl;
  return 0;
}
