#include <bits/stdc++.h>
using namespace std;
const int N = 200011;
int n, k, a[N], b[N];
int v[N * 2], pre[N * 2], bia[N], num = 0;
int dp[N], son[N], ans, MID, MA[N], out[N];
bool fulf[N];
void addedge(int l, int r) {
  ++num;
  v[num] = r;
  pre[num] = bia[l];
  bia[l] = num;
}
void dfs(int l, int fa) {
  son[l] = 1;
  int r, ma[3] = {0, 0, 0}, tem = 0, k;
  for (int i = bia[l]; i != 0; i = pre[i]) {
    r = v[i];
    if (r == fa) continue;
    dfs(r, l);
    son[l] += son[r];
    if (son[r] == dp[r])
      tem += dp[r];
    else {
      k = 2;
      ma[k] = dp[r];
      while (k > 0 && ma[k] > ma[k - 1]) {
        swap(ma[k], ma[k - 1]);
        k--;
      }
    }
  }
  if (a[l] >= MID) {
    MA[l] = tem + ma[0] + ma[1] + 1;
    dp[l] = tem + ma[0] + 1;
  } else {
    dp[l] = 0;
    MA[l] = 0;
  }
}
void getful(int l, int fa) {
  if (a[l] < MID) fulf[l] = false;
  if (fulf[l] == false) return;
  int r;
  int R, cnt = 0;
  for (int i = bia[l]; i != 0; i = pre[i]) {
    r = v[i];
    if (r == fa) continue;
    if (dp[r] == son[r])
      ;
    else {
      cnt++;
      R = r;
    }
  }
  if (cnt == 0) {
    for (int i = bia[l]; i != 0; i = pre[i]) {
      r = v[i];
      if (r == fa) continue;
      fulf[r] = true;
      getful(r, l);
    }
  } else if (cnt == 1) {
    for (int i = bia[l]; i != 0; i = pre[i]) {
      r = v[i];
      if (r == fa) continue;
      fulf[r] = false;
    }
    fulf[R] = true;
    getful(R, l);
  } else {
    for (int i = bia[l]; i != 0; i = pre[i]) {
      r = v[i];
      if (r == fa) continue;
      fulf[r] = false;
    }
    return;
  }
}
bool check() {
  memset(fulf, 0, sizeof(fulf));
  fulf[1] = fulf[0] = true;
  dfs(1, 0);
  getful(1, 0);
  int tem;
  for (int i = 1; i <= n; i++) {
    tem = MA[i];
    if (fulf[i] == true) {
      tem += n - son[i];
    }
    if (tem >= k) return true;
  }
  return false;
}
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    b[i] = a[i];
  }
  sort(b + 1, b + n + 1);
  int l, r;
  for (int i = 1; i < n; i++) {
    scanf("%d%d", &l, &r);
    addedge(l, r);
    addedge(r, l);
  }
  l = 1;
  r = n;
  int mid;
  while (l + 1 < r) {
    mid = (l + r) / 2;
    MID = b[mid];
    if (check() == true) {
      l = mid;
    } else {
      r = mid - 1;
    }
  }
  while (l < n) {
    MID = b[l + 1];
    if (check())
      l++;
    else
      break;
  }
  cout << b[l];
}
