#include <bits/stdc++.h>
using namespace std;
int sz[1000000], f[1000000], maxx, a[1000000], n, m, hea[1000000], wen[1000000],
    nex[1000000], len, root = 1;
void add(int x, int y) {
  ++len;
  nex[len] = hea[x];
  wen[len] = y;
  hea[x] = len;
}
void dfs(int x, int y, int z) {
  int max1 = 0, max2 = 0;
  f[x] = sz[x] = 1;
  for (int i = hea[x]; i; i = nex[i])
    if (wen[i] != y) {
      dfs(wen[i], x, z);
      sz[x] += sz[wen[i]];
      if (sz[wen[i]] == f[wen[i]]) {
        f[x] += f[wen[i]];
      } else {
        if (f[wen[i]] > max1) {
          max2 = max1;
          max1 = f[wen[i]];
        } else if (f[wen[i]] > max2)
          max2 = f[wen[i]];
      }
    }
  if (a[x] < z)
    f[x] = 0;
  else
    f[x] += max1;
  maxx = max(maxx, f[x] + max2);
}
int check(int x) {
  maxx = 0;
  dfs(root, 0, x);
  return (maxx >= m);
}
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++)
    if (a[root] > a[i]) root = i;
  for (int i = 1; i < n; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    add(x, y);
    add(y, x);
  }
  int l = 0, r = 1000000, mid = 500000;
  do {
    if (check(mid))
      l = mid;
    else
      r = mid;
    mid = (l + r) >> 1;
  } while (l + 1 < r);
  printf("%d", l);
}
