#include <bits/stdc++.h>
using namespace std;
long long rdtsc() {
  long long tmp;
  asm("rdtsc" : "=A"(tmp));
  return tmp;
}
inline int myrand() { return abs((rand() << 15) ^ rand()); }
inline int rnd(int x) { return myrand() % x; }
void precalc() {}
const int maxn = 2e5 + 10;
int n, k;
int a[maxn];
vector<int> to[maxn];
vector<int> num[maxn];
vector<int> dp[maxn];
vector<int> cnt[maxn];
vector<int> mx[maxn][2];
bool read() {
  if (scanf("%d%d", &n, &k) < 2) {
    return false;
  }
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
  }
  for (int i = 0; i < n; ++i) {
    to[i].clear();
    num[i].clear();
  }
  for (int i = 0; i < n - 1; ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    --a, --b;
    num[a].push_back(((int)(to[b]).size())),
        num[b].push_back(((int)(to[a]).size()));
    to[a].push_back(b), to[b].push_back(a);
  }
  return true;
}
int ldp[maxn];
int calcDp(int v, int pr, int mn) {
  if (dp[v][pr] != -1) {
    return dp[v][pr];
  }
  int &res = dp[v][pr];
  if (a[v] < mn) {
    res = 0;
    return res;
  }
  res = 1;
  if (ldp[v] == -1) {
    mx[v][0][pr] = mx[v][1][pr] = 0;
    for (int i = 0; i < ((int)(to[v]).size()); ++i) {
      if (i == pr) {
        continue;
      }
      int u = to[v][i], nm = num[v][i];
      int cur = calcDp(u, nm, mn);
      if (cur == cnt[u][nm]) {
        res += cur;
      } else {
        if (mx[v][1][pr] < cur) {
          mx[v][1][pr] = cur;
          if (mx[v][0][pr] < mx[v][1][pr]) {
            swap(mx[v][0][pr], mx[v][1][pr]);
          }
        }
      }
    }
    res += mx[v][0][pr];
    ldp[v] = pr;
  } else {
    res = dp[v][ldp[v]];
    int cmx = mx[v][0][ldp[v]];
    res -= cmx;
    if (pr < ((int)(to[v]).size())) {
      int u = to[v][pr], nm = num[v][pr];
      int cur = calcDp(u, nm, mn);
      if (cur == cnt[u][nm]) {
        res -= cur;
      } else if (cur == cmx) {
        cmx = mx[v][1][ldp[v]];
      }
    }
    if (ldp[v] < ((int)(to[v]).size())) {
      int u = to[v][ldp[v]], nm = num[v][ldp[v]];
      int cur = calcDp(u, nm, mn);
      if (cur == cnt[u][nm]) {
        res += cur;
      } else {
        cmx = max(cmx, cur);
      }
    }
    res += cmx;
  }
  return res;
}
bool good(int mn) {
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < ((int)(dp[i]).size()); ++j) {
      dp[i][j] = -1;
    }
    ldp[i] = -1;
  }
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < ((int)(dp[i]).size()); ++j) {
      ans = max(ans, calcDp(i, j, mn));
    }
  }
  return ans >= k;
}
int lcnt[maxn];
int calcCnt(int v, int pr) {
  if (cnt[v][pr] != -1) {
    return cnt[v][pr];
  }
  int &res = cnt[v][pr];
  res = 1;
  if (lcnt[v] == -1) {
    for (int i = 0; i < ((int)(to[v]).size()); ++i) {
      if (i == pr) {
        continue;
      }
      res += calcCnt(to[v][i], num[v][i]);
    }
  } else {
    res = cnt[v][lcnt[v]];
    if (lcnt[v] < ((int)(to[v]).size())) {
      res += calcCnt(to[v][lcnt[v]], num[v][lcnt[v]]);
    }
    if (pr < ((int)(to[v]).size())) {
      res -= calcCnt(to[v][pr], num[v][pr]);
    }
  }
  lcnt[v] = pr;
  return res;
}
void solve() {
  for (int i = 0; i < n; ++i) {
    mx[i][0] = vector<int>(((int)(to[i]).size()) + 1);
    mx[i][1] = vector<int>(((int)(to[i]).size()) + 1);
    dp[i] = vector<int>(((int)(to[i]).size()) + 1);
    cnt[i] = vector<int>(((int)(to[i]).size()) + 1, -1);
    lcnt[i] = -1;
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < ((int)(cnt[i]).size()); ++j) {
      calcCnt(i, j);
    }
  }
  int L = 0, R = (int)1e6 + 1;
  while (R - L > 1) {
    int M = (L + R) / 2;
    if (good(M)) {
      L = M;
    } else {
      R = M;
    }
  }
  printf("%d\n", L);
}
int main() {
  srand(rdtsc());
  precalc();
  while (true) {
    if (!read()) {
      break;
    }
    solve();
  }
  return 0;
}
