#include <bits/stdc++.h>
using namespace std;
vector<int> v[2000005];
int sz[2000005];
int a[2000005];
int MAX;
int root;
int DFS(int u, int p, int mid) {
  sz[u] = 1;
  int res = 1, m1 = 0, m2 = 0;
  for (auto it : v[u]) {
    if (p == it) continue;
    int f = DFS(it, u, mid);
    sz[u] += sz[it];
    if (f == sz[it])
      res += f;
    else if (f > m1) {
      m2 = m1;
      m1 = f;
    } else if (f > m2)
      m2 = f;
  }
  if (a[u] < mid) return 0;
  MAX = max(MAX, res + m1 + m2);
  return res + m1;
}
int check(int n) {
  MAX = 0;
  int x = DFS(root, -1, n);
  MAX = max(MAX, x);
  return MAX;
}
int main() {
  int n, m, x, y, mid;
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n - 1; i++) {
    cin >> x >> y;
    x--;
    y--;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  int low = 0;
  int high = 90000007;
  root = min_element(a, a + n) - a;
  int ans = 0;
  while (low <= high) {
    mid = low + (high - low) / 2;
    if (check(mid) >= m) {
      low = mid + 1;
      ans = max(ans, mid);
    } else {
      high = mid - 1;
    }
  }
  cout << ans << endl;
}
