#include <bits/stdc++.h>
using namespace std;
const int MN = 2e5 + 100;
int t[MN];
int cutoff = 0;
vector<int> edges[MN];
int dp[2 * MN];
int type[2 * MN];
int used[MN];
int n, k;
int laskuri = 0;
int f1(int x) {
  used[x] = 1;
  int res1 = 0;
  int res2 = 0;
  for (auto y : edges[x]) {
    if (!used[y]) {
      int q = f1(y);
      if (type[y]) {
        type[x] = 1;
        res2 = max(res2, q);
      } else {
        res1 += q;
      }
    }
  }
  if (t[x] < cutoff) {
    type[x] = 1;
    return dp[x] = 0;
  }
  return dp[x] = res1 + res2 + 1;
}
int f2(int x, int up, int upType) {
  used[x] = 1;
  int res1 = 0;
  pair<int, int> res2 = {0, 0};
  int type1Cnt = 0;
  if (upType == 1) ++type1Cnt;
  if (upType == 0) {
    res1 += up;
  } else {
    res2.first = up;
  }
  for (auto y : edges[x]) {
    if (!used[y]) {
      if (type[y]) {
        ++type1Cnt;
        if (dp[y] > res2.first) {
          res2.second = res2.first;
          res2.first = dp[y];
        } else if (dp[y] > res2.second) {
          res2.second = dp[y];
        }
      } else {
        res1 += dp[y];
      }
    }
  }
  int ans = 0;
  if (t[x] >= cutoff) {
    ans = res1 + res2.first + res2.second + 1;
  }
  for (auto y : edges[x]) {
    if (!used[y]) {
      if (t[x] < cutoff) {
        ans = max(ans, f2(y, 0, 1));
      } else {
        if (type[y] == 1) {
          int newUp = res2.first;
          if (newUp == dp[y]) newUp = res2.second;
          if (type1Cnt > 1) {
            ans = max(ans, f2(y, res1 + newUp + 1, 1));
          } else {
            ans = max(ans, f2(y, res1 + 1, 0));
          }
        }
      }
    }
  }
  return ans;
}
int solve(int mid) {
  cutoff = mid;
  for (int i = 0; i < 2 * MN; ++i) {
    dp[i] = -1;
    type[i] = 0;
  }
  memset(used, 0, sizeof used);
  f1(1);
  memset(used, 0, sizeof used);
  int ans = f2(1, 0, 0);
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= n; ++i) {
    cin >> t[i];
  }
  for (int i = 0; i < n - 1; ++i) {
    int a, b;
    cin >> a >> b;
    edges[a].push_back(b);
    edges[b].push_back(a);
  }
  int lo = 0;
  int hi = 1e6;
  int best = 0;
  while (lo <= hi) {
    int mid = (lo + hi) / 2;
    if (solve(mid) >= k) {
      best = mid;
      lo = mid + 1;
    } else {
      hi = mid - 1;
    }
  }
  cout << best << '\n';
}
