#include <bits/stdc++.h>
#pragma comment(linker, "/stack:16777216")
using namespace std;
const int INF = 1000000000;
const int BASE = 1000000007;
const int MAX = 200007;
const int MAX2 = 7777;
const int MAXE = 100000;
const int ADD = 1000000;
const int MOD = 1000000007;
const int CNT = 800;
int n, k;
vector<int> G[MAX];
int a[MAX];
bool U[MAX];
int res;
int cnt;
int c[MAX];
int d[MAX];
void dfs2(int v, int p) {
  c[v] = U[v];
  d[v] = 1;
  for (int i = (0); i < (G[v].size()); i++) {
    int to = G[v][i];
    if (to == p) continue;
    dfs2(to, v);
    c[v] += c[to];
    d[v] += d[to];
  }
}
pair<int, int> dfs(int v, int p) {
  vector<int> A;
  vector<int> B;
  bool bad = 0;
  for (int i = (0); i < (G[v].size()); i++) {
    int to = G[v][i];
    if (to == p) continue;
    if (U[to]) {
      bad = 1;
    }
    pair<int, int> pr = dfs(to, v);
    if (pr.second == 0) {
      A.push_back(pr.first);
    } else {
      bad = 1;
      B.push_back(pr.first);
    }
  }
  if (U[v]) return make_pair(0, 1);
  sort(B.begin(), B.end());
  reverse(B.begin(), B.end());
  int add = 1;
  for (int i = (0); i < (A.size()); i++) {
    add += A[i];
  }
  int add2 = add;
  if (B.size() > 0) add += B[0];
  if (B.size() > 1) add += B[1];
  if (cnt == c[v]) {
    add += n - d[v];
  }
  res = max(res, add);
  if (B.size() > 0) add2 += B[0];
  return make_pair(add2, bad);
}
bool check(int X) {
  memset(U, 0, sizeof(U));
  cnt = 0;
  for (int i = (0); i < (n); i++) {
    if (a[i] < X) {
      U[i] = 1;
      cnt++;
    }
  }
  dfs2(0, -1);
  res = 0;
  dfs(0, -1);
  return res >= k;
}
int main() {
  cin >> n >> k;
  for (int i = (0); i < (n); i++) {
    scanf("%d", &a[i]);
  }
  for (int i = (0); i < (n - 1); i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    --a;
    --b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  int L = 0;
  int R = 1000007;
  while (R - L > 1) {
    int X = (L + R) / 2;
    if (check(X)) {
      L = X;
    } else {
      R = X;
    }
  }
  cout << L << endl;
  return 0;
}
