#include <bits/stdc++.h>
using namespace std;
vector<int> adj[200010];
int bl[200010];
int mx[200010];
int fmx[200010];
int smx[200010];
int sz[200010];
int vis[200010];
int A[200010];
int b[200010];
const int all = (1e8);
int N, K, S;
int dfs1(int v, int p) {
  vis[v] = 1;
  if (bl[v]) {
    mx[v] = 0;
    sz[v] = 0;
    return 0;
  }
  int i, u, sum = 1;
  sz[v] = 1;
  b[v] = 0;
  fmx[v] = smx[v] = 0;
  for (i = 0; i < adj[v].size(); ++i) {
    u = adj[v][i];
    if (u == p) continue;
    sz[v] += dfs1(u, v);
    if (mx[u] == all) {
      sum += sz[u];
      continue;
    }
    b[v]++;
    if (mx[u] > fmx[v]) {
      smx[v] = fmx[v];
      fmx[v] = mx[u];
    } else {
      smx[v] = max(smx[v], mx[u]);
    }
  }
  sum += fmx[v];
  mx[v] = b[v] ? sum : all;
  return sz[v];
}
int best(int v, int p) {
  int i, u, sl;
  if (bl[v]) return 0;
  sl = 0;
  int mxpar = 0;
  if (p >= 0) {
    mxpar = mx[p];
    if (mxpar == all || (mx[v] != all && b[p] == 1))
      mxpar = all;
    else {
      if (mx[v] == all)
        mxpar -= sz[v];
      else if (mx[v] == fmx[p])
        mxpar += smx[p] - fmx[p];
    }
    if (mxpar != all) b[v]++;
  }
  if (mxpar == all) {
    if (mx[v] != all) mx[v] += S - sz[v];
  } else {
    if (mx[v] == all) mx[v] = sz[v];
    mx[v] -= fmx[v];
    if (mxpar > fmx[v]) {
      smx[v] = fmx[v];
      fmx[v] = mxpar;
    } else {
      smx[v] = max(smx[v], mxpar);
    }
    mx[v] += fmx[v];
  }
  sl = max(sl, (mx[v] == all ? S : mx[v]));
  for (i = 0; i < adj[v].size(); ++i) {
    u = adj[v][i];
    if (u == p) continue;
    sl = max(sl, best(u, v));
  }
  return sl;
}
int check(int lim) {
  int i;
  for (i = 0; i < N; ++i) bl[i] = (A[i] < lim), vis[i] = 0;
  int mx1 = 0;
  for (i = 0; i < N; ++i) {
    if (vis[i] || bl[i]) continue;
    dfs1(i, -1);
    S = sz[i];
    mx1 = max(mx1, best(i, -1));
  }
  return mx1 >= K;
}
int search() {
  int low, high, mid;
  low = 1, high = 1e6;
  while (low < high) {
    mid = low + (high - low + 1) / 2;
    if (check(mid)) {
      low = mid;
    } else {
      high = mid - 1;
    }
  }
  return low;
}
int main() {
  int i;
  scanf("%d%d", &N, &K);
  for (i = 0; i < N; ++i) scanf("%d", &A[i]);
  int u, v;
  for (i = 0; i < N - 1; ++i) {
    scanf("%d%d", &u, &v);
    --u, --v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  printf("%d\n", search());
  return 0;
}
