#include <bits/stdc++.h>
using namespace std;
int n, k, *a, *u, *v;
int *deg, *sdeg, *adj;
int maxdfs, *vis;
pair<int, bool> dfs(int idx, int brk) {
  if (a[idx] < brk) return make_pair(0, false);
  if (vis[idx] == 1) return make_pair(0, true);
  vis[idx] = 1;
  int hi1 = 0;
  int hi2 = 0;
  int fre = 0;
  bool b = true;
  for (int i = 0; i < deg[idx]; i++) {
    int nbr = adj[sdeg[idx] + i];
    pair<int, bool> result = dfs(nbr, brk);
    if (result.second) {
      fre += result.first;
    } else {
      b = false;
      if (result.first > hi2) hi2 = result.first;
      if (hi2 > hi1) swap(hi1, hi2);
    }
  }
  if (b) {
    return make_pair(fre + 1, true);
  } else {
    maxdfs = max(maxdfs, hi1 + hi2 + fre + 1);
    return make_pair(hi1 + fre + 1, false);
  }
}
int binsearch(int lo, int hi) {
  if (lo + 1 == hi) return lo;
  int mid = lo + (hi - lo) / 2;
  maxdfs = 0;
  vis = (int *)calloc(n, sizeof(int));
  for (int i = 0; i < n; i++) {
    if (vis[i] == 0 && a[i] >= mid) {
      for (int j = 0; j < deg[i]; j++) {
        if (a[adj[sdeg[i] + j]] < mid) {
          dfs(i, mid);
          break;
        }
      }
    }
  }
  free(vis);
  if (maxdfs >= k)
    return binsearch(mid, hi);
  else
    return binsearch(lo, mid);
}
int main() {
  scanf("%d %d", &n, &k);
  a = (int *)malloc(n * sizeof(int));
  int mina = 1000000;
  for (int i = 0; i < n; i++) {
    scanf("%d", a + i);
    mina = min(mina, a[i]);
  }
  deg = (int *)calloc(n, sizeof(int));
  u = (int *)malloc((n - 1) * sizeof(int));
  v = (int *)malloc((n - 1) * sizeof(int));
  for (int i = 0; i < n - 1; i++) {
    int u1, v1;
    scanf("%d %d", &u1, &v1);
    u[i] = u1 - 1;
    v[i] = v1 - 1;
    deg[u[i]]++;
    deg[v[i]]++;
  }
  sdeg = (int *)malloc(n * sizeof(int));
  sdeg[0] = 0;
  for (int i = 1; i < n; i++) sdeg[i] = sdeg[i - 1] + deg[i - 1];
  adj = (int *)malloc(2 * (n - 1) * sizeof(int));
  free(deg);
  deg = (int *)calloc(n, sizeof(int));
  for (int i = 0; i < n - 1; i++) {
    adj[sdeg[u[i]] + deg[u[i]]] = v[i];
    adj[sdeg[v[i]] + deg[v[i]]] = u[i];
    deg[u[i]]++;
    deg[v[i]]++;
  }
  printf("%d\n", binsearch(mina, 1000001));
  return 0;
}
