#include <bits/stdc++.h>
using namespace std;
const long double pi = 3.1415926535897932384626433832795l;
template <typename T>
inline auto sqr(T x) -> decltype(x * x) {
  return x * x;
}
template <typename T1, typename T2>
inline bool umx(T1& a, T2 b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T1, typename T2>
inline bool umn(T1& a, T2 b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
struct Input {
  int n, k;
  vector<int> a;
  vector<pair<int, int> > ed;
  bool read() {
    if (!(cin >> n >> k)) {
      return false;
    }
    a.resize(n);
    for (int i = 0; i < n; ++i) {
      scanf("%d", &a[i]);
    }
    for (int i = 0; i + 1 < n; ++i) {
      int u, v;
      scanf("%d%d", &u, &v);
      --u, --v;
      ed.push_back(make_pair(u, v));
    }
    return true;
  }
  void init(const Input& input) { *this = input; }
};
struct Data : Input {
  int ans;
  void write() { cout << ans << "\n"; }
  virtual void solve() {}
  virtual void clear() { *this = Data(); }
};
const int N = 2e5;
struct Solution : Data {
  vector<pair<int, int> > g[N];
  list<pair<int, int> > q[N];
  pair<pair<int, int>, pair<int, int> > acc[N];
  pair<int, int> d[3 * N];
  int bound;
  bool includedInAcc(int u, int w) {
    return w != -1 &&
           find_if((q[u]).begin(), (q[u]).end(), [&w](pair<int, int> const& x) {
             return x.first == w;
           }) == q[u].end();
  }
  void update(pair<pair<int, int>, pair<int, int> >& a,
              pair<int, int> const& b) {
    if (b.first == 0) {
      a.first.second += b.second;
    } else {
      ++a.first.first;
      if (a.second.first < b.second) {
        a.second.second = a.second.first;
        a.second.first = b.second;
      } else if (a.second.second < b.second) {
        a.second.second = b.second;
      }
    }
  }
  pair<int, int> extract(pair<pair<int, int>, pair<int, int> > const& a,
                         pair<int, int> const& b) {
    pair<int, int> r;
    if (a.first.first - b.first == 0) {
      r.first = 0;
      r.second = a.first.second - (b.first ? 0 : b.second);
    } else {
      r.first = 1;
      if (b.first == 0) {
        r.second = a.first.second - b.second + a.second.first;
      } else {
        r.second =
            a.first.second +
            ((a.second.first == b.second) ? a.second.second : a.second.first);
      }
    }
    return r;
  }
  pair<int, int>& get(int u, int w, int e) {
    return d[(w == -1) ? (2 * (n - 1) + u) : e];
  }
  pair<int, int> go(int u, int w = -1, int e = -1) {
    if (a[u] < bound) {
      return pair<int, int>(1, 0);
    }
    pair<pair<int, int>, pair<int, int> >& ra = acc[u];
    for (auto it = q[u].begin(); it != q[u].end();) {
      int v = it->first, f = it->second;
      if (w == v) {
        ++it;
        continue;
      }
      update(ra, go(v, u, f));
      it = q[u].erase(it);
    }
    pair<int, int>& r = get(u, w, e);
    r = extract(ra, (includedInAcc(u, w) ? get(w, u, e ^ 1) : make_pair(0, 0)));
    ++r.second;
    return r;
  }
  bool ok(int x) {
    bound = x;
    for (int i = 0; i < n; ++i) {
      acc[i] = make_pair(make_pair(0, 0), make_pair(0, 0));
      q[i].clear();
      q[i].insert(q[i].begin(), (g[i]).begin(), (g[i]).end());
    }
    for (int i = 0; i < n; ++i) {
      if (go(i).second >= k) {
        return true;
      }
    }
    return false;
  }
  void solve() {
    for (int i = 0; i < ((int)(ed).size()); ++i) {
      int u = ed[i].first, v = ed[i].second;
      g[u].push_back(make_pair(v, 2 * i));
      g[v].push_back(make_pair(u, 2 * i + 1));
    }
    vector<int> b = a;
    sort((b).begin(), (b).end());
    int left = 0, right = ((int)(b).size());
    while (left + 1 < right) {
      int middle = (left + right) / 2;
      if (ok(b[middle])) {
        left = middle;
      } else {
        right = middle;
      }
    }
    ans = b[left];
  }
  void clear() { *this = Solution(); }
};
Solution sol;
int main() {
  cout.setf(ios::showpoint | ios::fixed);
  cout.precision(20);
  sol.read();
  sol.solve();
  sol.write();
  return 0;
}
