#include <bits/stdc++.h>
using namespace std;
const int MN = 200010;
struct Fenwick {
  vector<int> tree;
  void init() { tree = vector<int>(MN + 1, 0); }
  void upd(int idx, int val) {
    for (int i = idx + 1; i <= MN; i += (i & -i)) tree[i] += val;
  }
  int quer(int a) {
    int ret = 0;
    for (int i = a + 1; i >= 1; i -= (i & -i)) ret += tree[i];
    return ret;
  }
  int quer(int a, int b) { return quer(b) - quer(a - 1); }
} bit;
int N, K;
int A[MN];
vector<int> X;
vector<int> adj[MN];
unordered_map<int, int> inva[MN];
int chk[MN], sz[MN], tin[MN], tout[MN], timer;
void dfs0(int u, int p) {
  tin[u] = timer++;
  sz[u] = 1;
  for (int i = 0; i < adj[u].size(); i++) {
    int v = adj[u][i];
    if (v == p) continue;
    dfs0(v, u);
    sz[u] += sz[v];
  }
  tout[u] = timer;
}
int dp1(int u, int p);
vector<pair<int, int> > cc3[MN];
pair<int, int> dp3(int u, int p) {
  if (p >= adj[u].size()) return pair<int, int>(0, 0);
  pair<int, int> &ret = cc3[u][p];
  if (ret != pair<int, int>(-1, -1)) return ret;
  ret = dp3(u, p + 1);
  int v = adj[u][p];
  if (tin[u] < tin[v]) {
    if (bit.quer(tin[v], tout[v] - 1) == 0)
      ret.first += sz[v];
    else if (!chk[v])
      ret.second = max(ret.second, dp1(v, inva[v][u]));
  } else {
    if (bit.quer(MN - 1) - bit.quer(tin[u], tout[u] - 1) == 0)
      ret.first += N - sz[u];
    else if (!chk[v])
      ret.second = max(ret.second, dp1(v, inva[v][u]));
  }
  return ret;
}
vector<pair<int, int> > cc2[MN];
pair<int, int> dp2(int u, int p) {
  if (p == -1) return pair<int, int>(0, 0);
  pair<int, int> &ret = cc2[u][p];
  if (ret != pair<int, int>(-1, -1)) return ret;
  ret = dp2(u, p - 1);
  int v = adj[u][p];
  if (tin[u] < tin[v]) {
    if (bit.quer(tin[v], tout[v] - 1) == 0)
      ret.first += sz[v];
    else if (!chk[v])
      ret.second = max(ret.second, dp1(v, inva[v][u]));
  } else {
    if (bit.quer(MN - 1) - bit.quer(tin[u], tout[u] - 1) == 0)
      ret.first += N - sz[u];
    else if (!chk[v])
      ret.second = max(ret.second, dp1(v, inva[v][u]));
  }
  return ret;
}
vector<int> cc1[MN];
int dp1(int u, int p) {
  int &ret = cc1[u][p];
  if (ret != -1) return ret;
  pair<int, int> t1 = dp2(u, p - 1);
  pair<int, int> t2 = dp3(u, p + 1);
  return ret = 1 + t1.first + t2.first + max(t1.second, t2.second);
}
bool f(int x) {
  for (int i = 0; i < N; i++) chk[i] = A[i] < x;
  bit.init();
  for (int i = 0; i < N; i++)
    if (A[i] < x) {
      bit.upd(tin[i], 1);
    }
  for (int i = 0; i < N; i++) {
    cc1[i] = vector<int>(adj[i].size() + 1, -1);
    cc2[i] = cc3[i] =
        vector<pair<int, int> >(adj[i].size(), pair<int, int>(-1, -1));
  }
  int Mx = 0;
  for (int i = 0; i < N; i++) {
    if (!chk[i]) {
      Mx = max(Mx, dp1(i, adj[i].size()));
    }
  }
  return Mx >= K;
}
int main() {
  scanf("%d %d", &N, &K);
  for (int i = 0; i < N; i++) {
    scanf("%d", &A[i]);
    X.push_back(A[i]);
  }
  sort(X.begin(), X.end());
  X.resize(unique(X.begin(), X.end()) - X.begin());
  for (int i = 0; i < N - 1; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    u--;
    v--;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  for (int u = 0; u < N; u++) {
    for (int i = 0; i < adj[u].size(); i++) {
      int v = adj[u][i];
      inva[u][v] = i;
    }
  }
  dfs0(0, -1);
  int s = 0, e = (int)X.size() - 1, p = -1;
  while (s <= e) {
    int m = (s + e) >> 1;
    if (f(X[m])) {
      p = m;
      s = m + 1;
    } else
      e = m - 1;
  }
  printf("%d", X[p]);
}
