#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}
vector<int> g[200005];
int val[200005];
int n, k;
bool bad[200005];
int DP[200005];
int deg[200005];
int ben[200005];
queue<int> Q;
int maxr = 0;
int solve(int u, int p) {
  DP[u] = ben[u];
  int c1 = -1;
  int c2 = -1;
  for (int j = 0; j < ((int)(g[u].size())); ++j) {
    int v = g[u][j];
    if (v == p) continue;
    DP[u] = max(DP[u], solve(v, u) + ben[u]);
    if (DP[v] <= c1) {
      if (DP[v] > c2) c2 = DP[v];
    } else {
      c2 = c1;
      c1 = DP[v];
    }
  }
  maxr = max(maxr, DP[u]);
  maxr = max(maxr, ben[u] + c1 + c2);
  return DP[u];
}
bool used[200005];
bool can(int x) {
  maxr = 0;
  memset(bad, 0, sizeof(bad));
  ;
  memset(used, 0, sizeof(used));
  ;
  for (int i = 0; i < n; ++i) {
    deg[i] = g[i].size();
    if (val[i] < x) {
      bad[i] = 1;
      ben[i] = -(1LL << 28);
    } else
      ben[i] = 1;
    if (!bad[i] && deg[i] == 1) Q.push(i);
  }
  while (!Q.empty()) {
    int u = Q.front();
    Q.pop();
    used[u] = 1;
    for (int j = 0; j < ((int)(g[u].size())); ++j) {
      int v = g[u][j];
      if (!bad[v]) {
        if (!used[v]) {
          ben[v] += ben[u];
          ben[u] = 0;
          deg[v]--;
          if (deg[v] == 1) Q.push(v);
        }
      }
    }
  }
  memset(DP, -1, sizeof(DP));
  solve(0, -1);
  return maxr >= k;
}
int main() {
  scanf("%d %d", &n, &k);
  int mini = 1 << 30;
  for (int i = 0; i < n; ++i) {
    scanf("%d", &val[i]);
    mini = min(mini, val[i]);
  }
  int u, v;
  for (int j = 0; j < n - 1; ++j) {
    scanf("%d %d", &u, &v);
    --u;
    --v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  int lo = 0;
  int hi = 1 << 29;
  int ans = -1;
  while (lo <= hi) {
    int mid = lo + (hi - lo) / 2;
    if (can(mid)) {
      ans = mid;
      lo = mid + 1;
    } else
      hi = mid - 1;
  }
  printf("%d", ans);
  puts("");
}
