#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
struct node {
  int x, y, next;
} edge[N << 1];
int len, first[N];
void ins(int x, int y) {
  len++;
  edge[len].x = x;
  edge[len].y = y;
  edge[len].next = first[x];
  first[x] = len;
}
inline int read() {
  int p = 0;
  int f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    p = p * 10 + (ch - '0');
    ch = getchar();
  }
  return p * f;
}
int a[N], n, f[N], g[N], siz[N], K;
pair<int, int> mx[N][2];
int mid;
void dfs(int x, int fa) {
  siz[x] = 1;
  if (a[x] >= mid) f[x] = 1;
  for (int k = first[x]; k != -1; k = edge[k].next) {
    int y = edge[k].y;
    if (y == fa) continue;
    dfs(y, x);
    siz[x] += siz[y];
    if (a[y] < mid) continue;
    if (f[y] == siz[y])
      f[x] += f[y];
    else {
      if (f[y] + mx[y][0].first > mx[x][0].first)
        mx[x][1] = mx[x][0], mx[x][0] = make_pair(f[y] + mx[y][0].first, y);
      else if (f[y] + mx[y][0].first > mx[x][1].first)
        mx[x][1] = make_pair(f[y] + mx[y][0].first, y);
    }
  }
  if (a[x] < mid) f[x] = 0;
}
void dfs2(int x, int fa) {
  for (int k = first[x]; k != -1; k = edge[k].next) {
    int y = edge[k].y;
    if (y == fa) continue;
    int s = f[x];
    int p = 0;
    if (siz[y] == f[y])
      s -= f[y];
    else if (y == mx[x][0].second)
      p = mx[x][1].first;
    else
      p = mx[x][0].first;
    if (a[x] >= mid) {
      if (n - siz[x] == g[x])
        s += g[x];
      else
        p = max(p, g[x]);
      g[y] = s + p;
    } else
      g[y] = 0;
    dfs2(y, x);
  }
}
bool check() {
  for (int i = 1; i <= n; i++)
    f[i] = g[i] = siz[i] = mx[i][0].first = mx[i][1].first = mx[i][0].second =
        mx[i][1].second = 0;
  dfs(1, 0);
  dfs2(1, 0);
  for (int i = 1; i <= n; i++)
    if (a[i] >= mid) {
      int s = 0;
      int p = 0;
      if (n - siz[i] == g[i])
        s = f[i] + g[i];
      else
        s = f[i], p = max(p, g[i]);
      p = max(p, mx[i][0].first);
      if (s + p >= K) return 1;
    }
  return 0;
}
int main() {
  n = read();
  K = read();
  memset(first, -1, sizeof(first));
  len = 0;
  for (int i = 1; i <= n; i++) a[i] = read();
  for (int i = 1; i < n; i++) {
    int x = read();
    int y = read();
    ins(x, y);
    ins(y, x);
  }
  mid = 372;
  check();
  int L = 1;
  int R = 1e9;
  int ret;
  while (L <= R) {
    mid = (L + R) >> 1;
    if (check())
      ret = mid, L = mid + 1;
    else
      R = mid - 1;
  }
  return printf("%d\n", ret), 0;
}
