#include <bits/stdc++.h>
using namespace std;
int n;
int k;
int a[200002];
vector<int> v[200002];
vector<int> vv;
vector<int> dp[200002];
vector<bool> none[200002];
vector<bool> use[200002];
bool flag[200002];
bool calced[200002];
int pr[200002];
int cnt_true[200002];
vector<int> NONE_MAX[200002];
int SUM[200002];
inline int dfs(int a, int pre) {
  if (pre == -1) {
    pre = use[a].size() - 1;
  } else {
    pre = lower_bound(v[a].begin(), v[a].end(), pre) - v[a].begin();
  }
  if (use[a][pre]) {
    return pre;
  }
  dp[a][pre] = 0;
  use[a][pre] = true;
  none[a][pre] = flag[a];
  if (none[a][pre] == false) {
    return pre;
  }
  int none_max = 0;
  int sum = 0;
  if (pre == use[a].size() - 1) {
    for (int i = 0; i < v[a].size(); i++) {
      int go = v[a][i];
      int ii = dfs(go, a);
      none[a][pre] = (none[a][pre] & none[go][ii]);
      if (none[go][ii]) {
        sum += dp[go][ii];
      } else {
        none_max = max(none_max, dp[go][ii]);
      }
    }
    sum += none_max;
    dp[a][pre] = sum + 1;
    return pre;
  }
  if (calced[a]) {
    int go = v[a][pr[a]];
    int ind = dfs(v[a][pr[a]], a);
    int true_cnt = cnt_true[a];
    if (none[go][ind]) {
      true_cnt++;
    }
    int goo = v[a][pre];
    int indd = dfs(goo, a);
    if (none[goo][indd]) {
      true_cnt--;
    }
    if (true_cnt + 1 == v[a].size()) {
      none[a][pre] = true;
    } else {
      none[a][pre] = false;
    }
    int sum = SUM[a];
    int none_max = NONE_MAX[a].back();
    if (none[goo][indd] == false) {
      if (dp[goo][indd] == none_max) {
        none_max = NONE_MAX[a][NONE_MAX[a].size() - 2];
      }
    } else {
      sum -= dp[goo][indd];
    }
    if (none[go][ind] == false) {
      none_max = max(none_max, dp[go][ind]);
    } else {
      sum += dp[go][ind];
    }
    dp[a][pre] = sum + none_max + 1;
    return pre;
  } else {
    calced[a] = true;
    cnt_true[a] = 0;
    pr[a] = pre;
    SUM[a] = 0;
    NONE_MAX[a].clear();
    for (int i = 0; i < v[a].size(); i++) {
      if (i == pre) {
        continue;
      }
      int go = v[a][i];
      int ii = dfs(go, a);
      none[a][pre] = (none[a][pre] & none[go][ii]);
      if (none[go][ii]) {
        cnt_true[a]++;
      }
      if (none[go][ii]) {
        sum += dp[go][ii];
      } else {
        none_max = max(none_max, dp[go][ii]);
        NONE_MAX[a].push_back(dp[go][ii]);
      }
    }
    SUM[a] = sum;
    while (NONE_MAX[a].size() < 2) {
      NONE_MAX[a].push_back(0);
    }
    sort(NONE_MAX[a].begin(), NONE_MAX[a].end());
    sum += none_max;
    dp[a][pre] = sum + 1;
    return pre;
  }
  exit(1);
}
bool solve(int A) {
  for (int i = 0; i < n; i++) {
    use[i].assign(use[i].size(), false);
  }
  for (int i = 0; i < n; i++) {
    flag[i] = static_cast<bool>(a[i] >= A);
    calced[i] = false;
    SUM[i] = 0;
    NONE_MAX[i].clear();
  }
  for (int i = 0; i < n; i++) {
    int idd = dfs(i, -1);
    if (dp[i][idd] >= k) {
      return true;
    }
  }
  return false;
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    vv.push_back(a[i]);
  }
  sort(vv.begin(), vv.end());
  vv.erase(unique(vv.begin(), vv.end()), vv.end());
  reverse(vv.begin(), vv.end());
  for (int i = 1; i < n; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    a--;
    b--;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  for (int i = 0; i < n; i++) {
    sort(v[i].begin(), v[i].end());
  }
  for (int i = 0; i < n; i++) {
    dp[i].assign(v[i].size() + 1, 0);
    use[i].assign(v[i].size() + 1, false);
    none[i].assign(v[i].size() + 1, false);
  }
  int mint = 0;
  int maxt = vv.size() - 1;
  while (mint + 1 < maxt) {
    int mid = (mint + maxt) >> 1;
    if (solve(vv[mid])) {
      maxt = mid;
    } else {
      mint = mid + 1;
    }
  }
  while (mint <= maxt) {
    if (solve(vv[mint])) {
      printf("%d\n", vv[mint]);
      return 0;
    }
    mint++;
  }
  return 0;
}
