#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long INF = mod * mod;
const long double eps = 1e-8;
const long double pi = acos(-1.0);
int n, k;
int a[1 << 18];
struct edge {
  int to, cost;
};
vector<int> G[200000];
vector<vector<pair<int, int>>> memo;
void init(int id, int fr) {
  for (int j = 0; j < G[id].size(); j++) {
    int to = G[id][j];
    if (to == fr) continue;
    init(to, id);
    memo[id].push_back({-1, -1});
  }
}
int inf;
bool yes = false;
pair<int, int> dfs(int id, int fr) {
  if (a[id] < inf) {
    return {0, false};
  }
  pair<int, int> res = {1, true};
  vector<pair<int, int>> nex;
  vector<int> ids;
  for (int j = 0; j < G[id].size(); j++) {
    int to = G[id][j];
    if (to == fr) continue;
    pair<int, int> z = dfs(to, id);
    nex.push_back(z);
    memo[id][ids.size()] = z;
    ids.push_back(to);
  }
  int ma = -1;
  for (int j = 0; j < nex.size(); j++) {
    if (nex[j].second == true) {
      res.first += nex[j].first;
    } else {
      ma = max(ma, nex[j].first);
    }
  }
  if (ma < 0) {
    return res;
  } else {
    res.second = false;
    res.first += ma;
  }
  return res;
}
void dfs2(int id, int fr, pair<int, int> frs) {
  if (fr < 0) {
    if (a[id] < inf) {
      for (int j = 0; j < G[id].size(); j++) {
        int to = G[id][j];
        dfs2(to, id, {0, false});
      }
    } else {
      vector<pair<int, int>> v;
      vector<int> ids;
      for (int j = 0; j < G[id].size(); j++) {
        int to = G[id][j];
        v.push_back(memo[id][ids.size()]);
        ids.push_back(to);
      }
      vector<int> mal(v.size() + 1, -1);
      vector<int> mar(v.size() + 1, -1);
      for (int i = 0; i < v.size(); i++) {
        if (!v[i].second) {
          mal[i + 1] = max(mal[i], v[i].first);
        } else {
          mal[i + 1] = mal[i];
        }
      }
      for (int i = (int)v.size() - 1; i >= 0; i--) {
        if (!v[i].second) {
          mar[i] = max(mar[i + 1], v[i].first);
        } else {
          mar[i] = mar[i + 1];
        }
      }
      int sum = 1;
      for (int j = 0; j < v.size(); j++) {
        if (v[j].second) sum += v[j].first;
      }
      for (int j = 0; j < v.size(); j++) {
        int to = ids[j];
        if (v[j].second) {
          int ssum = sum - v[j].first;
          int ma = max(mal[j], mar[j + 1]);
          if (ma == -1) {
            dfs2(to, id, {ssum, true});
          } else {
            dfs2(to, id, {ssum + ma, false});
          }
        } else {
          int ssum = sum;
          int ma = max(mal[j], mar[j + 1]);
          if (ma == -1) {
            dfs2(to, id, {ssum, true});
          } else {
            dfs2(to, id, {ssum + ma, false});
          }
        }
      }
    }
  } else {
    if (a[id] < inf) {
      for (int j = 0; j < G[id].size(); j++) {
        int to = G[id][j];
        if (to == fr) continue;
        dfs2(to, id, {0, false});
      }
    } else {
      vector<pair<int, int>> v;
      vector<int> ids;
      for (int j = 0; j < G[id].size(); j++) {
        int to = G[id][j];
        if (to == fr) continue;
        if (memo[id][ids.size()].first >= 0) {
          v.push_back(memo[id][ids.size()]);
        } else {
          v.push_back(dfs(to, id));
        }
        ids.push_back(to);
      }
      v.push_back(frs);
      vector<int> mal(v.size() + 1, -1);
      vector<int> mar(v.size() + 1, -1);
      for (int i = 0; i < v.size(); i++) {
        if (!v[i].second) {
          mal[i + 1] = max(mal[i], v[i].first);
        } else {
          mal[i + 1] = mal[i];
        }
      }
      for (int i = (int)v.size() - 1; i >= 0; i--) {
        if (!v[i].second) {
          mar[i] = max(mar[i + 1], v[i].first);
        } else {
          mar[i] = mar[i + 1];
        }
      }
      int sum = 1;
      for (int j = 0; j < v.size(); j++) {
        if (v[j].second) sum += v[j].first;
      }
      int mma = 0;
      for (int j = 0; j < v.size(); j++) {
        if (!v[j].second) mma = max(mma, v[j].first);
      }
      if (sum + mma >= k) yes = true;
      for (int j = 0; j < v.size() - 1; j++) {
        int to = ids[j];
        if (v[j].second) {
          int ssum = sum - v[j].first;
          int ma = max(mal[j], mar[j + 1]);
          if (ma == -1) {
            dfs2(to, id, {ssum, true});
          } else {
            dfs2(to, id, {ssum + ma, false});
          }
        } else {
          int ssum = sum;
          int ma = max(mal[j], mar[j + 1]);
          if (ma == -1) {
            dfs2(to, id, {ssum, true});
          } else {
            dfs2(to, id, {ssum + ma, false});
          }
        }
      }
    }
  }
}
bool can() {
  yes = false;
  pair<int, int> z = dfs(0, -1);
  if (z.first >= k) return true;
  dfs2(0, -1, {0, 0});
  return yes;
}
void solve() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  memo.resize(n);
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  init(0, -1);
  int le = 0, ri = 1000001;
  while (ri - le > 1) {
    int mid = (le + ri) / 2;
    for (int i = 0; i < n; i++)
      for (int j = 0; j < memo[i].size(); j++) memo[i][j] = {-1, -1};
    inf = mid;
    if (can()) {
      le = mid;
    } else {
      ri = mid;
    }
  }
  cout << le << endl;
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  solve();
  return 0;
}
