#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void debug(const char* name, Arg1&& arg1) {
  cerr << name << ": " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void debug(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " | ";
  debug(comma + 1, args...);
}
const int INF = 1000000000 + 5;
const int N = 2e5 + 5;
const int M = 2e5 + 5;
const long long oo = LLONG_MAX;
const int mod = 1e9 + 7;
void max_self(int& a, int b) {
  if (a < b) a = b;
}
int n, k;
int a[N];
vector<int> v[N];
int subTree[N];
int subValid[N];
int valid[N];
int getSubTree(int u, int par) {
  subTree[u] = 1;
  for (int x : v[u]) {
    if (x == par) continue;
    subTree[u] += getSubTree(x, u);
  }
  return subTree[u];
}
int getSubValid(int u, int par) {
  subValid[u] = valid[u];
  for (int x : v[u]) {
    if (x == par) continue;
    subValid[u] += getSubValid(x, u);
  }
  return subValid[u];
}
int cnt;
int dfs(int u, int par) {
  if (!valid[u]) {
    for (int x : v[u]) {
      if (x != par) dfs(x, u);
    }
    return 0;
  }
  int now = 0;
  int max1 = 0, max2 = 0;
  for (int x : v[u]) {
    if (x != par) {
      int sub = dfs(x, u);
      if (subValid[x] == subTree[x]) {
        now += subValid[x];
      } else {
        if (sub >= max1) {
          max2 = max1;
          max1 = sub;
        } else {
          if (sub > max2) max2 = sub;
        }
      }
    }
  }
  int tot = now + max1 + max2 + 1;
  max_self(cnt, tot);
  if (n - subTree[u] == subValid[1] - subValid[u]) {
    max_self(cnt, tot + (n - subTree[u]));
  }
  return now + max1 + 1;
}
int numNode(int x) {
  cnt = 0;
  for (int i = 1; i <= n; ++i) valid[i] = (a[i] >= x);
  getSubValid(1, -1);
  dfs(1, -1);
  return cnt;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  for (int i = 0; i < n - 1; ++i) {
    int x, y;
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  getSubTree(1, -1);
  int low = 1, high = 1e6;
  while (low < high) {
    int mid = (low + high + 1) >> 1;
    if (numNode(mid) >= k)
      low = mid;
    else
      high = mid - 1;
  }
  cout << low;
  return 0;
}
