#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
const int inf = 0x7f7f7f7f;
const int mod = 1000000007;
int a[N], dp[N];
vector<int> G[N];
int ans = 0;
int dfs(int u, int p, int mid) {
  dp[u] = 1;
  int cnt = 1, mx1 = 0, mx2 = 0;
  for (int i = 0; i < G[u].size(); i++) {
    int v = G[u][i];
    if (v == p) continue;
    int cur = dfs(v, u, mid);
    if (cur != dp[v]) {
      if (cur > mx1) {
        mx2 = mx1;
        mx1 = cur;
      } else if (cur > mx2)
        mx2 = cur;
    } else
      cnt += cur;
    dp[u] += dp[v];
  }
  if (a[u] < mid) return 0;
  ans = max(ans, cnt + mx1 + mx2);
  return cnt + mx1;
}
int main() {
  int n, u, v, K;
  scanf("%d%d", &n, &K);
  for (int i = 1; i <= n; i++) {
    scanf("%d", a + i);
  }
  for (int i = 0; i < n - 1; i++) {
    scanf("%d %d", &u, &v);
    G[u].push_back(v);
    G[v].push_back(u);
  }
  for (int i = 1; i <= n; i++) {
    if (a[i] < a[u]) u = i;
  }
  int l = a[u], r = 1000001, mid;
  while (l < r) {
    mid = (l + r) / 2 + 1;
    ans = 0;
    dfs(u, 0, mid);
    if (ans >= K) {
      l = mid;
    } else
      r = mid - 1;
  }
  printf("%d\n", l);
  return 0;
}
