#include <bits/stdc++.h>
using namespace std;
int n, k;
int u;
vector<vector<pair<int, int>>> adj(200010);
int a[200010];
int state[200010];
int lastproc[200010];
int freesum[200010];
int edgeend[200010 * 2];
int maxfinal[2][200010];
int maxfinalid[2][200010];
int bad[200010];
int good[200010];
int par[200010];
int root[200010];
void addinfo(int v, int r, int lid) {
  if (a[v] < u) {
    if (0 > maxfinal[0][r]) {
      maxfinal[0][r] = 0;
      maxfinalid[0][r] = v;
    } else if (0 > maxfinal[1][r]) {
      maxfinal[1][r] = 0;
      maxfinalid[1][r] = v;
    }
    return;
  }
  if (state[v] == 2) {
    bool risfree = false;
    if (par[v] == r) {
      risfree = bad[root[r]] == bad[v];
    } else {
      risfree = bad[r] == 0;
    }
    int cans = freesum[v];
    bool visfree = true;
    if (maxfinalid[0][v] == r) {
      if (maxfinal[1][v] != -1) {
        visfree = false;
        cans += maxfinal[1][v];
      }
    } else {
      if (maxfinal[0][v] != -1) {
        visfree = false;
        cans += maxfinal[0][v];
      }
    }
    if (risfree) {
      if (par[r] == v) {
        cans -= good[r];
      } else
        cans -= good[root[r]] - good[v];
    }
    if (visfree) {
      freesum[r] += cans;
    } else {
      if (cans > maxfinal[0][r]) {
        maxfinal[1][r] = maxfinal[0][r];
        maxfinalid[1][r] = maxfinalid[0][r];
        maxfinal[0][r] = cans;
        maxfinalid[0][r] = v;
      } else if (cans > maxfinal[1][r]) {
        maxfinal[1][r] = cans;
        maxfinalid[1][r] = v;
      }
    }
  } else {
    assert(state[v] == 1);
    int cans = freesum[v];
    int cadd = maxfinal[0][v] == -1 ? 0 : maxfinal[0][v];
    cans += cadd;
    if (maxfinal[0][v] == -1) {
      freesum[r] += cans;
    } else {
      if (cans > maxfinal[0][r]) {
        maxfinal[1][r] = maxfinal[0][r];
        maxfinalid[1][r] = maxfinalid[0][r];
        maxfinal[0][r] = cans;
        maxfinalid[0][r] = v;
      } else if (cans > maxfinal[1][r]) {
        maxfinal[1][r] = cans;
        maxfinalid[1][r] = v;
      }
    }
  }
}
void recur(int v, int pid) {
  if (a[v] < u) return;
  if (state[v] == 2) {
    return;
  }
  if (state[v] == 1) {
    if ((pid ^ 1) == lastproc[v]) {
      return;
    }
    int nx = lastproc[v];
    recur(edgeend[nx], nx);
    addinfo(edgeend[nx], v, nx);
    state[v] = 2;
    return;
  }
  if (state[v] == 0) {
    for (auto nx : adj[v]) {
      if (nx.second == (pid ^ 1)) continue;
      recur(nx.first, nx.second);
      addinfo(nx.first, v, nx.second);
    }
    state[v] = 1;
    lastproc[v] = pid ^ 1;
  }
}
int getans(int r) {
  if (a[r] < u) {
    return 0;
  }
  if (state[r] == 1) {
    int nval = lastproc[r];
    recur(edgeend[nval], nval);
    addinfo(edgeend[nval], r, nval);
  } else if (state[r] == 0) {
    for (auto v : adj[r]) {
      recur(v.first, v.second);
      addinfo(v.first, r, v.second);
    }
  }
  state[r] = 2;
  int mf = maxfinal[0][r] == -1 ? 0 : maxfinal[0][r];
  return freesum[r] + mf;
}
void predfs(int v) {
  good[v] = 1;
  if (par[v] == -1) {
    root[v] = v;
  }
  bad[v] = 0;
  for (auto x : adj[v]) {
    if (x.first == par[v]) continue;
    if (a[x.first] < u) {
      bad[v]++;
      continue;
    }
    root[x.first] = root[v];
    par[x.first] = v;
    predfs(x.first);
    bad[v] += bad[x.first];
    good[v] += good[x.first];
  }
}
bool check() {
  int best = 0;
  fill(state, state + 200010, 0);
  fill(maxfinal[0], maxfinal[0] + 200010, -1);
  fill(maxfinal[1], maxfinal[1] + 200010, -1);
  fill(maxfinalid[0], maxfinalid[0] + 200010, -1);
  fill(maxfinalid[1], maxfinalid[1] + 200010, -1);
  fill(freesum, freesum + 200010, 1);
  fill(par, par + 200010, -1);
  for (int i = 1; i <= n; i++) {
    if (a[i] >= u && par[i] == -1) predfs(i);
  }
  for (int i = 1; i <= n; i++) {
    best = max(best, getans(i));
  }
  return best >= k;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> k;
  int u1, v;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  int cid = -1;
  for (int i = 0; i < n - 1; i++) {
    cin >> u1 >> v;
    cid++;
    adj[u1].push_back({v, cid});
    edgeend[cid] = v;
    cid++;
    adj[v].push_back({u1, cid});
    edgeend[cid] = u1;
  }
  int lo = 1;
  int hi = 1000000;
  while (lo < hi) {
    int mid = (lo + hi + 1) / 2;
    u = mid;
    if (check()) {
      lo = mid;
    } else {
      hi = mid - 1;
    }
  }
  cout << lo << endl;
  cin >> n;
}
