#include <bits/stdc++.h>
using namespace std;
inline int in() {
  int x;
  scanf("%d", &x);
  return x;
}
inline void priv(vector<int> a) {
  for (int i = 0; i < ((int)(a).size()); ++i)
    printf("%d%c", a[i], i == (int)(a).size() - 1 ? '\n' : ' ');
}
template <typename T>
istream& operator>>(istream& i, vector<T>& v) {
  for (T& x : v) i >> x;
  return i;
}
template <typename T>
string join(vector<T>& v) {
  stringstream s;
  for (T& x : v) s << ' ' << x;
  return s.str().substr(1);
}
template <typename T>
ostream& operator<<(ostream& o, vector<T>& v) {
  if ((int)(v).size()) o << join(v);
  return o;
}
const int MX = 200005, INF = 1001001001;
const long long int LINF = 1e18;
const double eps = 1e-10;
int n, m, x;
int c[MX];
vector<int> to[MX];
int used[MX];
int root;
void rfs(int v, int p = -1) {
  used[v] = 1;
  for (int u : to[v])
    if (u != p) {
      if (c[u] < x)
        root = v;
      else
        rfs(u, v);
    }
}
int mx;
int dp[MX];
int dfs(int v, int p = -1) {
  int s = 1;
  bool ok = true;
  int nx = 0;
  dp[v] = 0;
  for (int u : to[v])
    if (u != p) {
      if (c[u] < x)
        ok = false;
      else {
        int ns = dfs(u, v);
        s += ns;
        if (!ns) {
          ok = false;
          nx = max(nx, dp[v] + dp[u]);
          dp[v] = max(dp[v], dp[u]);
        }
      }
    }
  nx += s;
  mx = max(mx, nx);
  dp[v] += s;
  if (!ok) s = 0;
  return s;
}
bool f() {
  for (int i = 0; i < (n); ++i) used[i] = 0;
  for (int i = 0; i < (n); ++i)
    if (!used[i] && c[i] >= x) {
      root = -1;
      rfs(i);
      if (root == -1) return true;
      mx = 0;
      dfs(root);
      if (mx >= m) return true;
    }
  return false;
}
int main() {
  scanf("%d", &n);
  scanf("%d", &m);
  for (int i = 0; i < (n); ++i) scanf("%d", &c[i]);
  for (int i = 0; i < (n - 1); ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    --a;
    --b;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  int l = 0, r = 1000001;
  while (l + 1 < r) {
    x = (l + r) >> 1;
    if (f())
      l = x;
    else
      r = x;
  }
  cout << l << endl;
  return 0;
}
