#include <bits/stdc++.h>
using namespace std;
const long long linf = 1e18 + 5;
const int mod = (int)1e9 + 7;
const int logN = 17;
const int inf = 1e9;
const int N = 2e5 + 5;
int all_cnt, sum[N], cnt[N], all[N], ok[N], n, m, a[N], x, y, z;
vector<int> v[N];
int dfs(int node, int root, int big) {
  cnt[node] = a[node] < big;
  all[node] = 1;
  sum[node] = 1;
  ok[node] = 1;
  int mx = 0, mx2 = 0;
  for (__typeof(v[node].begin()) it = v[node].begin(); it != v[node].end();
       it++) {
    if (*it == root) continue;
    if (dfs(*it, node, big)) return true;
    sum[node] += sum[*it];
    cnt[node] += cnt[*it];
    if (ok[*it] == 1)
      all[node] += all[*it];
    else {
      ok[node] = 0;
      if (all[*it] >= mx) {
        mx2 = mx;
        mx = all[*it];
      } else
        mx2 = max(mx2, all[*it]);
    }
  }
  all[node] += mx;
  if (a[node] < big) {
    all[node] = 0;
    ok[node] = 0;
  } else if (all[node] + mx2 + (cnt[node] == all_cnt ? n - sum[node] : 0) >= m)
    return true;
  return false;
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 2; i <= n; i++) {
    scanf("%d %d", &x, &y);
    v[x].push_back(y);
    v[y].push_back(x);
  }
  int bas = 0, son = 1000000;
  while (bas < son) {
    int ort = bas + son >> 1;
    if (bas == ort) ort++;
    all_cnt = 0;
    for (int i = 1; i <= n; i++) all_cnt += a[i] < ort;
    if (dfs(1, 0, ort))
      bas = ort;
    else
      son = ort - 1;
  }
  cout << bas << '\n';
  return 0;
}
