#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fll;
const int MAX = 6e3 + 10;
vector<int> g[MAX];
int memo[MAX][MAX];
vector<int> r;
int dp(int u, int v) {
  int& p = memo[u][v];
  if (p != -1) return p;
  int ret = 1 + (r[u] < r[v]);
  function<void(int, int)> dfs = [&](int uu, int vv) {
    for (auto ww : g[vv])
      if (ww != uu) dfs(vv, ww);
    if (r[u] < r[vv]) ret = max(ret, 2);
    if (r[u] < r[uu]) ret = max(ret, 1 + dp(uu, vv));
  };
  for (int w : g[v])
    if (w != u) dfs(v, w);
  return p = ret;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  r.resize(n);
  for (int& i : r) cin >> i;
  vector<pair<int, int>> edg;
  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);
    edg.push_back({u, v});
    edg.push_back({v, u});
  }
  memset(memo, -1, sizeof memo);
  int ans = 0;
  for (auto [a, b] : edg) {
    ans = max(ans, dp(a, b));
  }
  cout << ans << '\n';
  return 0;
}
