#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
const int INF = (int)1e9;
const long long LINF = (long long)1e18;
const long double PI = 2 * acos((long double)0);
long long gcd(long long a, long long b) {
  long long r;
  while (b) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
long long fpow(long long n, long long k, int p = MOD) {
  long long r = 1;
  for (; k; k >>= 1) {
    if (k & 1) r = r * n % p;
    n = n * n % p;
  }
  return r;
}
template <class T>
void setmin(T& a, T val) {
  if (a > val) a = val;
}
template <class T>
void setmax(T& a, T val) {
  if (a < val) a = val;
}
void addmod(int& a, int val, int p = MOD) {
  if ((a = (a + val)) >= p) a -= p;
}
void submod(int& a, int val, int p = MOD) {
  if ((a = (a - val)) < 0) a += p;
}
int mult(int a, int b, int p = MOD) { return (long long)a * b % p; }
int inv(int a, int p = MOD) { return fpow(a, p - 2, p); }
const int maxn = 200010;
int n, k;
int a[maxn];
vector<int> adj[maxn];
pair<int, int> f[maxn];
int d;
pair<int, int> dfs(int u, int p, int m) {
  pair<int, int>& res = f[u];
  if (~res.first) return res;
  res = make_pair(1, 1);
  int dmax = 0;
  for (int i = (0); i < (int((adj[u]).size())); i++) {
    int v = adj[u][i];
    if (v != p) {
      pair<int, int> r = dfs(v, u, m);
      res.first += r.first;
      if (r.first > r.second)
        setmax(dmax, r.second);
      else
        res.second += r.second;
    }
  }
  res.second += dmax;
  if (a[u] < m) {
    return res = make_pair(1, 0);
  }
  return res;
}
void dfs2(int u, int p, pair<int, int> val, int m) {
  vector<int> vt;
  vector<pair<int, int> > pref, suff;
  for (int i = (0); i < (int((adj[u]).size())); i++) {
    int v = adj[u][i];
    if (v != p) {
      vt.push_back(v);
      pref.push_back(f[v]);
      suff.push_back(f[v]);
    }
  }
  pair<int, int> t = make_pair(0, 0);
  vector<int> tmp;
  int sum = 0;
  for (int i = (0); i < (int((pref).size())); i++) {
    tmp.push_back(pref[i].first);
    sum += pref[i].first;
    if (pref[i].first == pref[i].second) {
      t.first += pref[i].first;
    } else {
      setmax(t.second, pref[i].second);
    }
    pref[i] = t;
  }
  t = make_pair(0, 0);
  for (int i = (int((suff).size())) - 1; i >= (0); i--) {
    if (suff[i].first == suff[i].second) {
      t.first += suff[i].first;
    } else {
      setmax(t.second, suff[i].second);
    }
    suff[i] = t;
  }
  for (int i = (0); i < (int((vt).size())); i++) {
    int v = vt[i];
    int x, y;
    if (val.first == val.second) {
      x = val.first;
      y = 0;
    } else {
      x = 0;
      y = val.second;
    }
    if (i) {
      x += pref[i - 1].first;
      setmax(y, pref[i - 1].second);
    }
    if (i < int((vt).size()) - 1) {
      x += suff[i + 1].first;
      setmax(y, suff[i + 1].second);
    }
    if (a[u] >= m) {
      x++;
    } else {
      x = y = 0;
    }
    dfs2(v, u, make_pair(val.first + sum - tmp[i] + 1, x + y), m);
  }
  if (a[u] >= m) {
    int x, y;
    if (val.first == val.second) {
      x = val.first;
      y = 0;
    } else {
      x = 0;
      y = val.second;
    }
    if (f[u].first == f[u].second) {
      x += f[u].first;
    } else {
      setmax(y, f[u].second);
    }
    setmax(d, x + y);
  }
}
void solve() {
  scanf("%d%d", &n, &k);
  for (int i = (0); i < (n); i++) scanf("%d", a + i);
  for (int i = (0); i < (n - 1); i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    u--;
    v--;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  int l = 1, r = 1000000;
  while (l < r) {
    int m = (l + r + 1) >> 1;
    memset(f, -1, sizeof(f));
    d = 0;
    dfs(0, -1, m);
    dfs2(0, -1, make_pair(0, 0), m);
    if (d >= k)
      l = m;
    else
      r = m - 1;
  }
  printf("%d", l);
}
int main() {
  solve();
  return 0;
}
