#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool getmin(T *a, const T &b) {
  if (b < *a) {
    *a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool getmax(T *a, const T &b) {
  if (b > *a) {
    *a = b;
    return true;
  }
  return false;
}
template <class T>
inline void read(T *a) {
  char c;
  while (isspace(c = getchar())) {
  }
  bool flag = 0;
  if (c == '-')
    flag = 1, *a = 0;
  else
    *a = c - 48;
  while (isdigit(c = getchar())) *a = *a * 10 + c - 48;
  if (flag) *a = -*a;
}
const int mo = 1000000007;
template <class T>
T pow(T a, T b, int c = mo) {
  T res = 1;
  for (T i = 1; i <= b; i <<= 1, a = 1LL * a * a % c)
    if (b & i) res = 1LL * res * a % c;
  return res;
}
const int N = 410000;
int n, cnt, m;
int head[N];
struct node {
  int p, nextt;
} edge[N];
int a[N];
bool flag[N];
void ae(int a, int b) {
  edge[++cnt].p = b;
  edge[cnt].nextt = head[a];
  head[a] = cnt;
}
int ans;
int f[N], size[N], g[N], t[N], p[N];
void dfs(int u, int fa) {
  size[u] = 1;
  int sum = 0, mx = 0, se = 0;
  p[u] = -1;
  for (int k = head[(u)]; k; k = edge[k].nextt) {
    int v = edge[k].p;
    if (v == fa) continue;
    dfs(v, u);
    size[u] += size[v];
    if (!flag[v]) continue;
    int x = f[v] + g[v] + 1;
    if (x == size[v])
      sum += x;
    else if (x > mx)
      se = mx, mx = x, p[u] = v;
    else if (x > se)
      se = x;
  }
  if (flag[u])
    f[u] = sum, g[u] = mx, t[u] = se;
  else
    f[u] = g[u] = t[u] = 0;
}
void solve(int u, int fa, int s) {
  if (flag[u]) {
    if (s == n - size[u])
      f[u] += s;
    else {
      if (s > g[u])
        t[u] = g[u], g[u] = s, p[u] = fa;
      else if (s > t[u])
        t[u] = s;
    }
    getmax(&ans, f[u] + g[u] + 1);
  }
  for (int k = head[(u)]; k; k = edge[k].nextt) {
    int v = edge[k].p;
    if (v == fa) continue;
    if (!flag[u])
      solve(v, u, 0);
    else {
      if (size[v] == f[v] + g[v] + flag[v])
        solve(v, u, f[u] - size[v] + g[u] + 1);
      else if (v == p[u])
        solve(v, u, f[u] + t[u] + 1);
      else
        solve(v, u, f[u] + g[u] + 1);
    }
  }
}
bool check(int x) {
  for (int i = (1); i <= (n); ++i) flag[i] = (a[i] >= x);
  dfs(1, 0);
  ans = 0;
  solve(1, 0, 0);
  return ans >= m;
}
int main() {
  cin >> n >> m;
  for (int i = (1); i <= (n); ++i) read(a + i);
  for (int i = (2); i <= (n); ++i) {
    int x, y;
    read(&x);
    read(&y);
    ae(x, y);
    ae(y, x);
  }
  int l = 1, r = 1000000, res;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (check(mid))
      res = mid, l = mid + 1;
    else
      r = mid - 1;
  }
  cout << res << endl;
  return 0;
}
